home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / text / show / mumo40.lha / MuchMore / Src / MuchMore.mod next >
Text File  |  1994-01-01  |  92KB  |  2,793 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.01
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                             (C.Stiens)
  65. :History.        24-Dec-92: New option -p for Password              (C.Stiens)
  66. :History.        24-Dec-92: New option -e for Extra Spacing         (C.Stiens)
  67. :History.        24-Dec-92: New option -c for Screen Colors         (C.Stiens)
  68. :History.        24-Dec-92: Tooltypes                               (C.Stiens)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more      (C.Stiens)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device               (C.Stiens)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always      (C.Stiens)
  72. :History.        10-Feb-93: ScreenMode Requester                    (C.Stiens)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode           (C.Stiens)
  74. :History.        10-Feb-93: Busy Pointer                            (C.Stiens)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start   (C.Stiens)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                 (C.Stiens)
  77. :History.        15-Feb-93: Bugs in GetString fixed                 (C.Stiens)
  78. :History.        19-Feb-93: More Scrollmodes                        (C.Stiens)
  79. :History.        20-Feb-93: Bug in Type() fixed                     (C.Stiens)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                (C.Stiens)
  81. :History.        08-Mar-93: New Option -t for Taskpri               (C.Stiens)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04        (C.Stiens)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft      (C.Stiens)
  84. :History.        19-Mar-93: New Option -o for one plane             (C.Stiens)
  85. :History.        19-Mar-93: New Option -a for tab width             (C.Stiens)
  86. :History.        19-Mar-93: Removed QText                           (C.Stiens)
  87. :History.        21-Mar-93: Opens screen with full overscan width   (C.Stiens)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3     (C.Stiens)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                    (C.Stiens)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more            (C.Stiens)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                     (C.Stiens)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes              (C.Stiens)
  93. :History. 3.2.10 16-May-93: Locale Support                          (C.Stiens)
  94. :History.        16-May-93: DispMode-Requester font-sensitive       (C.Stiens)
  95. :History.   V3.3 21-Jun-93: Code optimised                          (C.Stiens)
  96. :History.        25-Jun-93: Safe quit                               (C.Stiens)
  97. :History.   V3.4 29-Jun-93: Clipboard support                       (C.Stiens)
  98. :History.        29-Jun-93: took version number out of catalog      (C.Stiens)
  99. :History.   V3.5 31-Jul-93: case sensitive search, Boyer-Moore Alg. (C.Stiens)
  100. :History.   V3.6 15-Aug-93: Page up/down with softscroll reimpl.    (C.Stiens)
  101. :History.        16-Aug-93: Flash at EOF/BOF                        (C.Stiens)
  102. :History.   V3.7 28-Oct-93: New option E=EDITOR                     (C.Stiens)
  103. :History.        21-Nov-93: MM was not 100% pure (BusyPointer)      (C.Stiens)
  104. :History.        21-Nov-93: Password has to be entered in stringgad (C.Stiens)
  105. :History.   V4.0 07-Dec-93: MM can run in a WB Window               (C.Stiens)
  106. :History.        07-Dec-93: Options WINDOW, LEFT, TOP, WIDTH, HEIGHT(C.Stiens)
  107. :History.        07-Dec-93: Kick 1.3 is no more supported           (C.Stiens)
  108. :History.        07-Dec-93: Removed Options SCROLLMODE and NOOSCAN  (C.Stiens)
  109. :Contents.   A Soft-Scrolling ASCII-File Viewer.
  110. :Remark.     Compile: 'Oberon -svbcrntzdma MuchMore' for short code
  111. :Remark.     Compile: 'Oberon -dma MuchMore' for safe code
  112. :Remark.     Link:    'OLink -dma MuchMore'
  113. ---------------------------------------------------------------------------*)
  114.  
  115. MODULE MuchMore; (* $StackChk- *)
  116.  
  117. IMPORT gt := GadTools,
  118.        loc:= Locale,
  119.        ip := IFFParse,
  120.        u  := Utility,
  121.        con:= Console,
  122.        str:= Strings,
  123.        ie := InputEvent,
  124.        I  := Intuition,
  125.        g  := Graphics,
  126.        d  := Dos,
  127.        e  := Exec,
  128.        ol := OberonLib,
  129. (* $IF quiet *) NoRequesters, (* $END *)
  130.        SYS:= SYSTEM;
  131.  
  132. CONST
  133.   MuchText = "MuchMore 4.0 © 1988-94 AMOK\o$VER: muchmore 4.0 (1.1.94)";
  134.   Version = "v4.0";
  135.  
  136.   MSGOOM        = 0;
  137.   MSGCOS        = 1;
  138.   MSGCOW        = 2;
  139.   MSGCOF        = 3;
  140.   MSGRWERR      = 4;
  141.   MSGRETRYABORT = 5;
  142.   MSGEMPTY      = 6;
  143.   MSGSAVE       = 7;
  144.   MSGUSE        = 8;
  145.   MSGCANCEL     = 9;
  146.   MSGOK         = 10;
  147.   MSGCHOOSESM   = 11;
  148.   MSGINFOFMT    = 12;
  149.   MSGH1         = 13;
  150.   MSGH2         = 14;
  151.   MSGH3         = 15;
  152.   MSGH4         = 16;
  153.   MSGH5         = 17;
  154.   MSGH6         = 18;
  155.   MSGH7         = 19;
  156.   MSGH8         = 20;
  157.   MSGH9         = 21;
  158.   MSGH10        = 22;
  159.   MSGH11        = 23;
  160.   MSGH12        = 24;
  161.   MSGH13        = 25;
  162.   MSGH14        = 26;
  163.   MSGH15        = 27;
  164.   MSGH16        = 28;
  165.   MSGH17        = 29;
  166.   MSGH18        = 30;
  167.   MSGH19        = 31;
  168.   MSGH20        = 32;
  169.   MSGH21        = 33;
  170.   MSGH22        = 34;
  171.   MSGH23        = 35;
  172.   MSGH24        = 36;
  173.  
  174.  
  175.   TYPE
  176.     MSGTYPE = ARRAY 37 OF e.STRPTR;
  177.  
  178.   CONST
  179.  
  180.     MSGS = MSGTYPE(
  181.       SYS.ADR( "Out of memory"      ),
  182.       SYS.ADR( "Can't open screen"  ),
  183.       SYS.ADR( "Can't open window"  ),
  184.       SYS.ADR( "Can't open file"    ),
  185.       SYS.ADR( "Read/Write Error"   ),
  186.       SYS.ADR( "Retry|Abort"        ),
  187.       SYS.ADR( "File empty"         ),
  188.       SYS.ADR( "Save"               ),
  189.       SYS.ADR( "Use"                ),
  190.       SYS.ADR( "Cancel"             ),
  191.       SYS.ADR( " OK "               ),
  192.       SYS.ADR( "Choose Screen Mode:"),
  193.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  194.       SYS.ADR( "\x13                \x15  MuchMore %s Commands:  "),
  195.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  196.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  197.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  198.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  199.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  200.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  201.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  202.       SYS.ADR( " (\x0DShift\x05) \x0DF\x05, \x0DN\x05, \x0DP\x05:    \x0DF\x05ind string (case sensitive), \x0DN\x05ext, \x0DP\x05revious"),
  203.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  204.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  205.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line..."),
  206.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  207.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Print text"),
  208.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  209.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  210.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  211.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  212.       SYS.ADR( "© \x131988-94 Fridtjof Siebert & Christian Stiens"),
  213.       SYS.ADR( ""),
  214.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  215.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK"),
  216.       SYS.ADR( " \x0dC\x05:                  \x0dC\x05opy block between marker #1 and #2 to clipboard"),
  217.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d E\x05:    \x0dE\x05dit text") );
  218.  
  219.  
  220.  
  221. TYPE BusyPointer = ARRAY 36 OF INTEGER;
  222.  
  223. CONST TheBusyPointer = BusyPointer(
  224.   00000U,00000U,
  225.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  226.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  227.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  228.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  229.   00000U,00000U);
  230.  
  231.  
  232. CONST (* RawKey Codes: *)
  233.  
  234.   ESC   = 45H; HELP  = 5FH;
  235.   UP    = 4CH; DOWN  = 4DH;
  236.   SPACE = 40H; BS    = 41H;
  237.   CR    = 44H; ENTER = 43H;
  238.   NK0   = 0FH; NK1   = 1DH; NK2   = 1EH; NK3   = 1FH;
  239.   NK5   = 2EH; NK7   = 3DH; NK8   = 3EH; NK9   = 3FH;
  240.   F1    = 50H; F10   = 59H;
  241.  
  242.  
  243. CONST
  244.   ShowStackSize = 4096;
  245.   BufferSize = 2048;
  246.  
  247.   w = TRUE;
  248.   f = FALSE;
  249.  
  250.   MyIdcmp = LONGSET{I.inactiveWindow,I.activeWindow,I.rawKey,I.mouseButtons,I.closeWindow};
  251.  
  252. (* Control codes: *)
  253.   plain    = 11X;
  254.   italic   = 12X;
  255.   bold     = 13X;
  256.   boldit   = 14X;
  257.   ulineon  = 15X;
  258.   ulineoff = 16X;
  259.  
  260.   Italic = 0;
  261.   Bold   = 1;
  262.   Ulin   = 2;
  263.   Inv    = 3;
  264.  
  265. TYPE
  266.   String    = e.STRING;
  267.   StringPtr = e.STRPTR;
  268.   CharPtr   = UNTRACED POINTER TO CHAR;
  269.   LongPtr   = UNTRACED POINTER TO LONGINT;
  270.  
  271.   TextLinePtr = UNTRACED POINTER TO TextLine;
  272.   TextLine = STRUCT
  273.                prev : TextLinePtr;
  274.                next : TextLinePtr;
  275.                len  : INTEGER;
  276.                size : INTEGER;
  277.                text : String;
  278.              END;
  279.  
  280. CONST
  281.   MaxLen = SIZE(String);
  282.  
  283. TYPE
  284.  
  285.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  286.                    process    : d.ProcessId;
  287.                    segment    : e.BPTR;
  288.                    numArgs    : LONGINT;
  289.                    toolWindow : StringPtr;
  290.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  291.                                  lock : d.FileLockPtr;
  292.                                  name : StringPtr;
  293.                              END;
  294.                  END;
  295.  
  296.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  297.                     magic      : INTEGER;
  298.                     version    : INTEGER;
  299.                     gadget     : I.Gadget;
  300.                     type       : SHORTINT;
  301.                     defaultTool: StringPtr;
  302.                     toolTypes  : e.APTR;
  303.                     currentX   : LONGINT;
  304.                     currentY   : LONGINT;
  305.                     drawerData : e.APTR;
  306.                     toolWindow : StringPtr;
  307.                     stackSize  : LONGINT;
  308.                   END;
  309.  
  310.   Args = STRUCT (dummy: d.ArgsStruct)
  311.            b     : LongPtr;
  312.            c     : StringPtr;
  313.            d     : StringPtr;
  314.            e     : StringPtr;
  315.            f     : StringPtr;
  316.            o     : StringPtr;
  317.            p     : LongPtr;
  318.            t     : LongPtr;
  319.            x     : LongPtr;
  320.            w     : StringPtr;
  321.            wl    : LongPtr;
  322.            wt    : LongPtr;
  323.            ww    : LongPtr;
  324.            wh    : LongPtr;
  325.            file  : StringPtr;
  326.          END;
  327.  
  328. (*------  Memory:  ------*)
  329.  
  330. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  331.  
  332. TYPE
  333.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  334.  
  335.   MemChunk = STRUCT
  336.                prev: MemChunkPtr;     (* link *)
  337.                data: ARRAY ChunkSize OF CHAR; (* ChunkSize Bytes of memory *)
  338.              END;
  339.  
  340.  
  341. (*------  Globals  ------*)
  342.  
  343. VAR
  344.   pub            : I.ScreenPtr;        (* default public screen             *)
  345.   Screen         : I.ScreenPtr;        (* MuchMore's Screen                 *)
  346.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  347.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  348.   id             : LONGINT;            (* Display ID                        *)
  349.   Window         : I.WindowPtr;        (* My window                         *)
  350.   Win            : I.WindowPtr;        (* window for Find & Goto            *)
  351.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  352.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  353.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  354.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  355.   FontName       : String;             (* My Font Name or                   *)
  356.   FontSize       : INTEGER;            (* My Font Size                      *)
  357.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  358.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  359.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  360.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  361.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  362.   writeText      : TextLine;           (* temp. Text Line                   *)
  363.   Name,OldName   : String;             (* Text's Name                       *)
  364.   option         : String;             (* CLI Option                        *)
  365.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  366.   editcmd        : String;
  367.   Pens           : String;             (* Screen colors                     *)
  368.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  369.   busyPointer    : UNTRACED POINTER TO BusyPointer;
  370.   icon           : DiskObjectPtr;      (* info                              *)
  371.   nameptr        : StringPtr;          (* String Pointer                    *)
  372.   chptr          : CharPtr;            (* Char Pointer                      *)
  373.   PStr           : String;             (* The command for Dos.Execute       *)
  374.   Buffer         : UNTRACED POINTER TO ARRAY BufferSize OF CHAR; (* ReadBuf *)
  375.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  376.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  377.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  378.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  379.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  380.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  381.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  382.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  383.   i,j            : INTEGER;            (* count                             *)
  384.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  385.   left,top       : INTEGER;
  386.   width,height   : INTEGER;
  387.   depth          : INTEGER;
  388.   win            : BOOLEAN;
  389.   ci             : INTEGER;
  390.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  391.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  392.   progdir        : d.FileLockPtr;
  393.   clock          : d.FileLockPtr;
  394.   FileInfo       : d.FileInfoBlockPtr; (* to get File's length              *)
  395.   FileLength,TextLength: LONGINT;      (* Length of File and Displayed Text *)
  396.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  397.   ShowTask       : e.TaskPtr;          (* the task that displays the text   *)
  398.   ShowStack      : e.APTR;             (* it's stack                        *)
  399.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  400.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  401.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  402.   Done           : BOOLEAN;            (* Quit                              *)
  403.   print          : BOOLEAN;            (* print text?                       *)
  404.   save           : BOOLEAN;            (* save block?                       *)
  405.   copy           : BOOLEAN;            (* copy block to clipboard?          *)
  406.   NewText        : BOOLEAN;            (* load new text                     *)
  407.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  408.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  409.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  410.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  411.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  412.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  413.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  414.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  415.   oldstyle       : BOOLEAN;            (* Page Up/Down with soft scroll?    *)
  416.   lace           : BOOLEAN;            (* Is screen interlaced?             *)
  417.   cLocked        : BOOLEAN;
  418.   overscanTag    : LONGINT;            (* overscan tag                      *)
  419.   mySigBit       : INTEGER;            (* My SignalBit                      *)
  420.   mySig          : LONGSET;            (* My SignalSet = LONGSET{mySigBit}  *)
  421.   Me             : d.ProcessPtr;       (* my main task                      *)
  422.   meInt          : LONGINT;
  423.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  424.   frame          : INTEGER;            (* Frame Count                       *)
  425.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  426.   fg,bg          : INTEGER;            (* Text colors                       *)
  427.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  428.   style          : SHORTSET;           (* Text style                        *)
  429.   CommLine       : UNTRACED POINTER TO ARRAY 1000 OF CHAR;(* the CLI args   *)
  430.   tabw           : INTEGER;            (* Tabulator width                   *)
  431.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  432.   args           : Args;               (* My CLI Args                       *)
  433.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  434.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  435.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  436.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  437.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  438.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  439.   StrInfo        : I.StringInfo;       (* its special info                  *)
  440.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  441.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  442.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  443.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  444.   Filename       : String;             (* The Filename (without path)       *)
  445.   Dirname        : String;             (* its path                          *)
  446.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  447.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  448.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  449.   FindLine       : TextLinePtr;        (* Last found line                   *)
  450.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  451.   Password       : String;             (* Password for encrypted texts      *)
  452.   conreq         : e.IOStdReqPtr;      (* Console IO-Request                *)
  453.   console        : e.DevicePtr;        (* the console.device                *)
  454.   ievent         : ie.InputEventPtr;   (* InputEvent to convert keycodes    *)
  455.   WriteName      : String;             (* File to write Block               *)
  456.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  457.   iff            : ip.IFFHandlePtr;    (* IFF Handle for clipboard copy     *)
  458.   buffer         : UNTRACED POINTER TO CHAR; (* Save buffer                 *)
  459.   MemIndex       : INTEGER;            (* index in current Chunk            *)
  460.   CurChunk       : MemChunkPtr;        (* current chunk                     *)
  461.   c              : CHAR;               (* \ used by GetTextLine();          *)
  462.   le             : INTEGER;            (* / global for speed                *)
  463.  
  464.  
  465. (*-------------------------------------------------------------------------*)
  466.  
  467. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  468.  
  469. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  470. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  471. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  472.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  473. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  474.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  475.  
  476. (*-------------------------------------------------------------------------*)
  477.  
  478. (* $Debug- *)
  479.  
  480. PROCEDURE StuffChar; (* $EntryExitCode- *)
  481. BEGIN
  482.   SYS.INLINE(016C0U, 04E75U)
  483. END StuffChar;
  484.  
  485.  
  486. (*-------------------------------------------------------------------------*)
  487.  
  488.  
  489. PROCEDURE LocStr (num: LONGINT): e.STRPTR;
  490. VAR default: e.STRPTR;
  491.  
  492. BEGIN
  493.   default := MSGS[num];
  494.   IF loc.base=NIL THEN RETURN default
  495.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  496. END LocStr;
  497.  
  498.  
  499. (*-----------------------------  Requester:  ------------------------------*)
  500.  
  501.  
  502. PROCEDURE Request(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  503. VAR es: I.EasyStruct;
  504.  
  505. BEGIN
  506.   IF ol.wbStarted THEN
  507.     es.structSize   := SIZE(I.EasyStruct);
  508.     es.flags        := LONGSET{};
  509.     es.title        := SYS.ADR(MuchText);
  510.     es.textFormat   := SYS.ADR(Text);
  511.     es.gadgetFormat := LocStr(MSGOK);
  512.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN END;
  513.   ELSE
  514.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  515.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  516.   END;
  517.   HALT(d.fail);
  518. END Request;
  519.  
  520.  
  521. PROCEDURE OutOfMemHandler;
  522. VAR es: I.EasyStruct;
  523.  
  524. BEGIN
  525.   es.structSize   := SIZE(I.EasyStruct);
  526.   es.flags        := LONGSET{};
  527.   es.title        := SYS.ADR(MuchText);
  528.   es.textFormat   := LocStr(MSGOOM);
  529.   es.gadgetFormat := LocStr(MSGRETRYABORT);
  530.   IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  531.     HALT(d.fail)
  532.   END;
  533. END OutOfMemHandler;
  534.  
  535.  
  536. (*-------------------------------------------------------------------------*)
  537.  
  538.  
  539. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  540.  
  541. VAR newchunk: MemChunkPtr;
  542.  
  543. BEGIN
  544.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  545.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  546.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  547.   ELSE
  548.     NEW(newchunk);                   (* allocate new chunk                *)
  549.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  550.     CurChunk := newchunk;
  551.     MemIndex := sz;
  552.   END;
  553.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  554. END AllocLine;
  555.  
  556.  
  557. PROCEDURE DisposeLines();
  558.  
  559. VAR chunk: MemChunkPtr;
  560.  
  561. BEGIN
  562.   WHILE CurChunk#NIL DO
  563.     chunk := CurChunk.prev;
  564.     DISPOSE(CurChunk);
  565.     CurChunk := chunk;
  566.   END;
  567.   MemIndex := ChunkSize;
  568. END DisposeLines;
  569.  
  570.  
  571. (*-------------------------------------------------------------------------*)
  572.  
  573.  
  574. PROCEDURE Busy;
  575. BEGIN
  576.   IF Window#NIL THEN
  577.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  578.     I.SetPointer(Window,busyPointer^,16,16,-6,0);
  579.   END;
  580. END Busy;
  581.  
  582.  
  583. PROCEDURE UnBusy;
  584. BEGIN
  585.   IF Window#NIL THEN
  586.     I.ClearPointer(Window);
  587.     I.OldModifyIDCMP(Window,MyIdcmp);
  588.   END;
  589. END UnBusy;
  590.  
  591.  
  592. (*------  Scroll:  ------*)
  593.  
  594. PROCEDURE MakeScroll(sync,fast,always: BOOLEAN);
  595. VAR m: INTEGER;
  596.  
  597. BEGIN
  598.   IF Scrollable THEN
  599.     m := 1;
  600.     IF ~always THEN
  601.       IF lace & ~fast THEN m := 2 END;
  602.       IF ~sync THEN INC(m,m*2) END;
  603.     END;
  604.     IF (m=1) OR (frame MOD m=0) THEN
  605.       g.ScrollVPort(SYS.ADR(Screen.viewPort));
  606.       g.WaitTOF;
  607.     END;
  608.     (* $OvflChk- *)
  609.     INC(frame);
  610.     (* $OvflChk= *)
  611.   END;
  612. END MakeScroll;
  613.  
  614.  
  615. (*------  Clear Display:  ------*)
  616.  
  617. PROCEDURE ClearDisplay;
  618. BEGIN
  619.   IF win THEN
  620.     g.SetAPen(rp,0);
  621.     g.RectFill(rp,left,top,left+width-1,top+height-1);
  622.   ELSE
  623.     g.SetRast(rp,0);
  624.   END;
  625.   IF Scrollable THEN
  626.     ri.ryOffset := 0;
  627.     ScreenPos := 0;
  628.     MakeScroll(f,f,w);
  629.   END;
  630. END ClearDisplay;
  631.  
  632. (*-------------------------------------------------------------------------*)
  633.  
  634. (*------  Read one TextLine into a Variable:  ------*)
  635.  
  636.  
  637. PROCEDURE GetTextLine(): TextLinePtr;
  638. (* returns NIL at EOF *)
  639.  
  640. VAR
  641.   l        : TextLinePtr;
  642.   sz,wd,i,j: INTEGER;
  643.   txt      : ARRAY MaxLen+1 OF CHAR;
  644.   num      : ARRAY 10 OF INTEGER;
  645.   newcol   : BOOLEAN;
  646.   oldstyle : SHORTSET;
  647.  
  648.   PROCEDURE GetCh();
  649.   BEGIN
  650.     IF RQPos=RQLen THEN
  651.       RQLen := d.Read(MyFile,Buffer^,BufferSize);
  652.       IF RQLen<0 THEN Request(LocStr(MSGRWERR)^) END;
  653.       RQPos := 0;
  654.     END;
  655.     IF RQLen=0 THEN c := 0X ELSE
  656.       c := Buffer[RQPos]; IF c=0X THEN c:=1X END;
  657.       INC(RQPos); INC(le);
  658.     END;
  659.   END GetCh;
  660.  
  661. BEGIN
  662.   IF RQLen=0 THEN RETURN NIL END;
  663.   sz := 0; wd := 0; le := 0;
  664.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  665.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  666.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  667.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  668.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  669.   LOOP
  670.     LOOP
  671.       GetCh;
  672.       IF SYS.VAL(CHAR,SYS.VAL(SHORTSET,c)*SHORTSET{0..6})#1BX THEN EXIT END;
  673.       i := -1;
  674.       REPEAT
  675.         GetCh;
  676.         IF (c>=30X) & (c<=39X) THEN
  677.           INC(i); num[i] := 0;
  678.           REPEAT
  679.             num[i] := 10*num[i]+ORD(c)-ORD(30X); GetCh;
  680.           UNTIL (c<30X) OR (c>39X);
  681.         END;
  682.         c := CAP(c);
  683.       UNTIL (c>=3FX(*"?"*)) & (c<=5AX) OR (c=0X) OR (i=9);
  684.       IF c=4DX THEN
  685.         newcol := f; oldstyle := style; j := 0;
  686.         IF i=-1 THEN i:=0; num[0] := 0 END;
  687.         WHILE (i>=j) & (sz<MaxLen-1) DO
  688.           CASE num[j] OF
  689.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  690.           1:  INCL(style,Bold) |
  691.           2:  fg := 2; newcol := w |
  692.           3:  INCL(style,Italic) |
  693.           4:  INCL(style,Ulin) |
  694.           7:  INCL(style,Inv); newcol := w |
  695.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  696.  
  697.           22: EXCL(style,Bold); fg := 1; newcol := w |
  698.           23: EXCL(style,Italic) |
  699.           24: EXCL(style,Ulin) |
  700.           27: EXCL(style,Inv); newcol := w |
  701.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  702.  
  703.           30..37: fg := (num[j]-30) MOD 4; newcol := w |
  704.           39:     fg := 1; newcol := w |
  705.  
  706.           40..47: bg := (num[j]-40) MOD 4; newcol := w |
  707.           49:     bg := 0; newcol := w |
  708.  
  709.           ELSE END;
  710.           INC(j);
  711.         END;
  712.         IF (oldstyle#style) & (sz<MaxLen) THEN
  713.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  714.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  715.           END;
  716.           INC(sz);
  717.           IF (Ulin IN style) THEN
  718.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  719.               txt[sz] := ulineon;
  720.               INC(sz);
  721.             END;
  722.           ELSE
  723.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  724.               txt[sz] := ulineoff;
  725.               INC(sz);
  726.             END;
  727.           END;
  728.         END;
  729.         IF newcol & (sz<MaxLen) THEN
  730.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  731.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  732.           INC(sz);
  733.         END;
  734.       END;   (* IF c="m" THEN *)
  735.     END;   (* LOOP *)
  736.     CASE c OF
  737.       020X.. 7FX:   txt[sz] := c; INC(sz); INC(wd) |
  738.       0A1X..0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  739.       8X: (* BS *)  IF wd>0 THEN DEC(sz); DEC(wd); END |
  740.       9X: (* TAB *) REPEAT
  741.                       txt[sz] := 20X; INC(sz); INC(wd)
  742.                     UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  743.       0A0X:         txt[sz] := 20X; INC(sz); INC(wd) |
  744.       0AX,0X,0CX:   EXIT
  745.     ELSE
  746.     END;
  747.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  748.   END;
  749.   txt[sz] := 0X; INC(sz);
  750.   l := AllocLine(sz);
  751.   l.len := le; l.size:= sz;
  752.   WHILE sz>0 DO DEC(sz); l.text[sz] := txt[sz] END;
  753.   RETURN l;
  754. END GetTextLine;
  755.  
  756.  
  757. (*------  Write Line to Screen:  ------*)
  758.  
  759.  
  760. PROCEDURE Type(pos: INTEGER; line: TextLinePtr);
  761.  
  762. VAR
  763.   style: SHORTSET;
  764.   front,back: SHORTINT;
  765.   c: CHAR;
  766.   last,i,x,y: INTEGER;
  767.   strPtr: StringPtr;
  768.  
  769. BEGIN
  770.   g.SetDrMd(rp,g.jam2);
  771.   IF Scrollable THEN
  772.     g.SetAPen(rp,0);
  773.     y := pos * fontHeight;
  774.     IF ~refresh THEN g.RectFill(rp,0,y,width-1,y+fontHeight-spacing-1) END;
  775.   END;
  776.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  777.   LOOP
  778.     WHILE line.text[i] < " " DO
  779.       c := line.text[i];
  780.       IF c=0X THEN EXIT END;
  781.       CASE c OF
  782.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  783.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  784.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  785.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  786.       ulineon : INCL(style,g.underlined) |
  787.       ulineoff: EXCL(style,g.underlined) |
  788.       1X..10X : DEC(c);
  789.                 front := SHORT(ORD(c)) DIV 4;
  790.                 back  := SHORT(ORD(c)) MOD 4 |
  791.       ELSE END;
  792.       INC(i);
  793.     END;
  794.     strPtr := SYS.ADR(line.text[i]); last := i;
  795.     REPEAT INC(i) UNTIL line.text[i]<" ";
  796.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  797.     g.SetAPen(rp,front);
  798.     g.SetBPen(rp,back);
  799.     g.Move(rp,left+fontWidth*x,top+fontHeight*pos+fontBaseLine);
  800.     g.Text(rp,strPtr^,i-last);
  801.     INC(x,i-last);
  802.   END;
  803. END Type;
  804.  
  805.  
  806. PROCEDURE CopyScrollLine(pos: INTEGER);
  807. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden
  808.  * DoubleBuffer-Bereich
  809.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  810.  *)
  811.  
  812. VAR
  813.   y,z: INTEGER;
  814.  
  815. BEGIN
  816.   y := pos*fontHeight;
  817.   z := PageHeight;
  818.   IF pos >= NumLines THEN z := -z END;
  819.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  820. END CopyScrollLine;
  821.  
  822.  
  823. (*------  Copy String to TextLine:  ------*)
  824.  
  825.  
  826. PROCEDURE CopyToWriteText(String: StringPtr);
  827. VAR i,j : INTEGER;
  828.  
  829. BEGIN
  830.   e.CopyMem(String^,writeText.text,MaxLen-1);
  831.   j := 0;
  832.   FOR i := 0 TO SHORT(str.Length(writeText.text))-1 DO
  833.     IF writeText.text[i] >= " " THEN INC(j) END;
  834.     IF j >= NumColumns THEN
  835.       writeText.text[i] := 0X;
  836.       RETURN
  837.     END;
  838.   END;
  839. END CopyToWriteText;
  840.  
  841.  
  842. (*------  Write String to Screen (at any position):  ------*)
  843.  
  844.  
  845. PROCEDURE TypeTo(VAR text: TextLine; pos: INTEGER);
  846.  
  847. BEGIN
  848.   IF pos < NumLines THEN
  849.     IF Scrollable THEN
  850.       INC(pos,ScreenPos);
  851.       Type(pos,SYS.ADR(text));
  852.       CopyScrollLine(pos);
  853.     ELSE
  854.       Type(pos,SYS.ADR(text));
  855.     END;
  856.   END;
  857. END TypeTo;
  858.  
  859.  
  860. (*------  Write String to Screen (at any position):  ------*)
  861.  
  862.  
  863. PROCEDURE WriteTo(String: StringPtr; pos: INTEGER);
  864.  
  865. BEGIN
  866.   CopyToWriteText(String);
  867.   TypeTo(writeText,pos);
  868. END WriteTo;
  869.  
  870.  
  871. (*------  Write Line at Bottom of Text:  ------*)
  872.  
  873.  
  874. PROCEDURE AddBottomLine(Line: TextLinePtr; Fast: BOOLEAN);
  875. VAR i,y: INTEGER;
  876.  
  877. BEGIN
  878.   IF ~Scrollable THEN
  879.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  880.     IF Fast THEN
  881.       g.ScrollRaster(rp,0,fontHeight,left,top,left+width-1,top+height-1);
  882.       IF Sync THEN g.WaitTOF END;
  883.     ELSE
  884.       i := fontHeight;
  885.       REPEAT
  886.         g.ScrollRaster(rp,0,1,left,top,left+width-1,top+height-1);
  887.         IF Sync THEN g.WaitTOF END;
  888.         DEC(i);
  889.       UNTIL i=0;
  890.     END;
  891.     Type(NumLines-1,Line);
  892.   ELSE
  893.     Type(ScreenPos+NumLines,Line);
  894.     y := ScreenPos*fontHeight;
  895.     IF Fast THEN
  896.       INC(ri.ryOffset,fontHeight);
  897.       MakeScroll(Sync,w,f);
  898.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  899.     ELSE
  900.       i := fontHeight;
  901.       REPEAT
  902.         INC(ri.ryOffset);
  903.         MakeScroll(Sync,f,f);
  904.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,1, 0C0X, SHORTSET{0..7}, NIL));
  905.         INC(y);
  906.         DEC(i);
  907.       UNTIL i=0;
  908.     END;
  909.     INC(ScreenPos);
  910.     IF ScreenPos=NumLines THEN
  911.       ScreenPos := 0;
  912.       ri.ryOffset := 0;
  913.     END;
  914.   END;
  915. END AddBottomLine;
  916.  
  917.  
  918. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  919.  
  920.  
  921. PROCEDURE TryBottomnext(): BOOLEAN;
  922. (* returns TRUE if BottomLine.next#NIL END; *)
  923.  
  924. BEGIN
  925.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  926.     SignalNewData := w;
  927.     SYS.SETREG(0,e.Wait(mySig));
  928.     SignalNewData := f;
  929.   END;
  930.   RETURN BottomLine.next#NIL;
  931. END TryBottomnext;
  932.  
  933.  
  934. (*------  Scroll down one Line:  ------*)
  935.  
  936.  
  937. PROCEDURE ScrollDown(Fast: BOOLEAN);
  938.  
  939. BEGIN
  940.   IF TryBottomnext() THEN
  941.     BottomLine := BottomLine.next;
  942.     INC(AnzLines);
  943.     INC(TextLength,BottomLine.len);
  944.   ELSE RETURN END;
  945.   IF AnzLines >= NumLines THEN TopLine := TopLine.next END;
  946.   AddBottomLine(BottomLine,Fast);
  947. END ScrollDown;
  948.  
  949.  
  950. (*------  Scroll Up one Line:  ------*)
  951.  
  952.  
  953. PROCEDURE ScrUp (Fast: BOOLEAN);
  954. VAR
  955.   i,y: INTEGER;
  956.  
  957. BEGIN
  958.   IF ~Scrollable THEN
  959.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  960.     IF Fast THEN
  961.       g.ScrollRaster(rp,0,-fontHeight,left,top,left+width-1,top+height-1);
  962.       IF Sync THEN g.WaitTOF END;
  963.     ELSE
  964.       i := fontHeight;
  965.       REPEAT
  966.         g.ScrollRaster(rp,0,-1,left,top,left+width-1,top+height-1);
  967.         IF Sync THEN g.WaitTOF END;
  968.         DEC(i)
  969.       UNTIL i=0;
  970.     END;
  971.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  972.   ELSE
  973.     IF ScreenPos=0 THEN
  974.       ri.ryOffset  := NumLines*fontHeight;
  975.       ScreenPos := NumLines;
  976.     END;
  977.     DEC(ScreenPos);
  978.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  979.     y := ScreenPos*fontHeight;
  980.     IF Fast THEN
  981.       DEC(ri.ryOffset,fontHeight);
  982.       MakeScroll(Sync,w,f);
  983.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  984.     ELSE
  985.       INC(y,fontHeight);
  986.       i := fontHeight;
  987.       REPEAT
  988.         DEC(ri.ryOffset);
  989.         MakeScroll(Sync,f,f);
  990.         DEC(y);
  991.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,1, 0C0X, SHORTSET{0..7}, NIL));
  992.         DEC(i);
  993.       UNTIL i=0;
  994.     END;
  995.   END;
  996. END ScrUp;
  997.  
  998.  
  999. PROCEDURE ScrollUp(Fast: BOOLEAN);
  1000.  
  1001. BEGIN
  1002.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1003.     TopLine := TopLine.prev;
  1004.     DEC(TextLength,BottomLine.len);
  1005.     DEC(AnzLines);
  1006.     BottomLine := BottomLine.prev;
  1007.     ScrUp(Fast);
  1008.   END;
  1009. END ScrollUp;
  1010.  
  1011.  
  1012. (*------  Undo last AddBottomLine:  ------*)
  1013.  
  1014.  
  1015. PROCEDURE DelLine(Fast: BOOLEAN);
  1016.  
  1017. BEGIN
  1018.   ScrUp(Fast);
  1019.   Info := f;
  1020. END DelLine;
  1021.  
  1022.  
  1023. (*------  Convert String to Integer:  ------*)
  1024.  
  1025. PROCEDURE StrToInt(str: StringPtr; base: INTEGER): LONGINT;
  1026.  
  1027. VAR
  1028.   i,j: INTEGER;
  1029.   num: LONGINT;
  1030.   ch : CHAR;
  1031.   neg: BOOLEAN;
  1032.  
  1033. BEGIN
  1034.   num := 0; i := 0; neg := f;
  1035.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1036.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1037.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1038.   LOOP
  1039.     IF i=LEN(str^) THEN EXIT END;
  1040.     ch := CAP(str^[i]);
  1041.     IF ch=0X THEN EXIT END;
  1042.     j := ORD(ch);
  1043.     CASE ch OF
  1044.       "0".."9": DEC(j,ORD('0'))   |
  1045.       "A".."F": DEC(j,ORD('A')-10);
  1046.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1047.       ELSE EXIT
  1048.     END;
  1049.     num := num * base + j;
  1050.     INC(i);
  1051.   END;
  1052.   IF neg THEN num := -num END;
  1053.   RETURN num
  1054. END StrToInt;
  1055.  
  1056.  
  1057. (*-------------------------------------------------------------------------*)
  1058.  
  1059.  
  1060. PROCEDURE GetLength(t: TextLinePtr);
  1061.  
  1062. BEGIN
  1063.   TextLength := 0; AnzLines := 0;
  1064.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1065. END GetLength;
  1066.  
  1067.  
  1068. (*-------------------------------------------------------------------------*)
  1069.  
  1070.  
  1071. PROCEDURE NewDisplay;
  1072. (* Zeichnet ab BottomLine neu *)
  1073.  
  1074. VAR
  1075.   i: INTEGER;
  1076.   l: TextLinePtr;
  1077.  
  1078. BEGIN
  1079.   IF ~refresh THEN ClearDisplay END;
  1080.   l := BottomLine.prev;
  1081.   IF l#NIL THEN BottomLine := l END;
  1082.   l := BottomLine;
  1083.   i := NumLines-1;
  1084.   WHILE (i>0) & TryBottomnext() DO
  1085.     BottomLine := BottomLine.next;
  1086.     DEC(i);
  1087.   END;
  1088.   WHILE (i>0) & (l.prev#NIL) DO
  1089.     l := l.prev;
  1090.     DEC(i);
  1091.   END;
  1092.   TopLine := l.next;
  1093.   WHILE i<NumLines DO
  1094.     BottomLine := l;
  1095.     TypeTo(BottomLine^,i);
  1096.     INC(i);
  1097.     l := l.next;
  1098.   END;
  1099.   GetLength(BottomLine);
  1100.   Scroll := f;
  1101. END NewDisplay;
  1102.  
  1103.  
  1104. (*-------------------------------------------------------------------------*)
  1105.  
  1106.  
  1107. PROCEDURE GetString(VAR str: ARRAY OF CHAR; int,newdisp: BOOLEAN);
  1108. VAR
  1109.   msg: I.IntuiMessagePtr;
  1110.   class: LONGSET;
  1111.   l,t,w,h: INTEGER;
  1112.   waCustomScreen: LONGINT;
  1113.  
  1114. BEGIN
  1115.   waCustomScreen := I.waCustomScreen;
  1116.   MakeScroll(f,f,TRUE);
  1117.   Busy;
  1118.   w := width DIV 4 * 3;
  1119.   l := (width-w) DIV 2;
  1120.   t := height DIV 2;
  1121.   IF Screen # NIL THEN
  1122.     IF Scrollable THEN INC(t,ri.ryOffset) END;
  1123.     h := Screen.font.ySize+4;
  1124.   ELSE
  1125.     INC(l,Window.leftEdge);
  1126.     INC(t,Window.topEdge);
  1127.     h := Window.wScreen.font.ySize+4;
  1128.     waCustomScreen := u.done;
  1129.   END;
  1130.   StrGadget.leftEdge   := 4;
  1131.   StrGadget.topEdge    := 2;
  1132.   StrGadget.width      := w-8;
  1133.   StrGadget.height     := h-4;
  1134.   StrGadget.activation := {I.stringCenter,I.relVerify};
  1135.   IF int THEN INCL(StrGadget.activation,I.longint) END;
  1136.   StrGadget.gadgetType := I.strGadget;
  1137.   StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1138.   StrInfo.buffer       := SYS.ADR(str);
  1139.   StrInfo.maxChars     := SHORT(LEN(str))-1;
  1140.  
  1141.   IF Scrollable THEN Screen.height := Screen.height * 2 END;
  1142.  
  1143.   Win := I.OpenWindowTagsA(NIL,
  1144.                            I.waLeft,  l,
  1145.                            I.waTop,   t,
  1146.                            I.waWidth, w,
  1147.                            I.waHeight,h,
  1148.                            I.waIDCMP, LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow},
  1149.                            I.waFlags, LONGSET{I.rmbTrap,I.activate,I.noCareRefresh},
  1150.                            I.waGadgets,SYS.ADR(StrGadget),
  1151.                            waCustomScreen,Screen,
  1152.                            u.done);
  1153.  
  1154.   IF Scrollable THEN Screen.height := Screen.height DIV 2 END;
  1155.  
  1156.   IF Win # NIL THEN
  1157.     e.WaitPort(Win.userPort);
  1158.     SYS.SETREG(0,I.ActivateGadget(StrGadget,Win,NIL));
  1159.     LOOP
  1160.       e.WaitPort(Win.userPort);
  1161.       msg := e.GetMsg(Win.userPort);
  1162.       IF msg # NIL THEN
  1163.         class := msg.class;
  1164.         e.ReplyMsg(msg);
  1165.         IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1166.           EXIT
  1167.         END;
  1168.       END;
  1169.     END;
  1170.     I.CloseWindow(Win); Win := NIL;
  1171.   END;
  1172.   UnBusy;
  1173.   IF newdisp & ~win THEN
  1174.     refresh := TRUE; BottomLine := TopLine; NewDisplay; refresh := f;
  1175.   END;
  1176. END GetString;
  1177.  
  1178.  
  1179. (*-------------------------------------------------------------------------*)
  1180.  
  1181.  
  1182. PROCEDURE * ShowProc;
  1183.  
  1184. VAR
  1185.   l           : TextLinePtr;
  1186.   Down        : BOOLEAN;          (* Scroll-Direction                  *)
  1187.   Shift       : BOOLEAN;          (* Shifted Keystroke ?               *)
  1188.   Alt         : BOOLEAN;          (* Altered Keystroke ?               *)
  1189.   wasInfo     : BOOLEAN;          (* was Info line displayed ?         *)
  1190.   found       : BOOLEAN;          (* TRUE, if find was successful      *)
  1191.   chr         : CHAR;             (* converted keycode                 *)
  1192.   caseDelta   : SHORTINT;         (* Case sensitive Search?            *)
  1193.   flen        : INTEGER;          (* length of findstring              *)
  1194.   i,j         : INTEGER;          (* Count                             *)
  1195.   Class       : LONGSET;          (* contains Message.class            *)
  1196.   Code        : INTEGER;          (* contains Message.code             *)
  1197.   Qualifier   : SET;              (* contains Message.qualifier        *)
  1198.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capital findstring   *)
  1199.   Goto        : ARRAY 10 OF CHAR; (* string containing goto line #     *)
  1200.   li          : LONGINT;          (* longint value of line to go to    *)
  1201.   HiText      : TextLine;         (* Highlited textline                *)
  1202.   OldHiText   : TextLinePtr;      (* original, un-hilited text         *)
  1203.   skipTab     : ARRAY 256 OF INTEGER;(* for Boyer-Moore Alg.           *)
  1204.  
  1205.  
  1206.   PROCEDURE WaitAllRead();
  1207.  
  1208.   BEGIN
  1209.     IF MyFile#NIL THEN
  1210.       Busy;
  1211.       SignalAllRead := w;
  1212.       SYS.SETREG(0,e.Wait(mySig));
  1213.       SignalAllRead := f;
  1214.       UnBusy;
  1215.     END;
  1216.   END WaitAllRead;
  1217.  
  1218.  
  1219.   PROCEDURE HiLite(at,len: INTEGER);
  1220.   (* Hilites len chars of BottomLine.text starting at position at *)
  1221.  
  1222.   VAR
  1223.     c: INTEGER;
  1224.     col: CHAR;
  1225.  
  1226.   BEGIN
  1227.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1228.     IF at+len+2<MaxLen THEN
  1229.       c := 0; col := 5X;
  1230.       WHILE c<at DO
  1231.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1232.         INC(c);
  1233.       END;
  1234.       HiText.text[at] := CHR(17-ORD(col));
  1235.       c := at; INC(len,at);
  1236.       WHILE c<len DO
  1237.         HiText.text[c+1] := OldHiText.text[c];
  1238.         INC(c);
  1239.       END;
  1240.       HiText.text[c+1] := col;
  1241.       REPEAT
  1242.         HiText.text[c+2] := OldHiText.text[c];
  1243.         INC(c);
  1244.       UNTIL HiText.text[c-1]=0X;
  1245.     END;
  1246.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1247.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1248.   END HiLite;
  1249.  
  1250.  
  1251.   PROCEDURE UnHiLite();
  1252.  
  1253.   BEGIN
  1254.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1255.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1256.   END UnHiLite;
  1257.  
  1258.  
  1259.   PROCEDURE CalcSkipTab;  (* Make skip-table for Boyer-Moore Alg. *)
  1260.   VAR i,j: INTEGER;
  1261.  
  1262.   BEGIN
  1263.     FOR i := 0 TO 255 DO skipTab[i] := flen END;
  1264.     i := 0;
  1265.     FOR j := flen-1 TO 0 BY -1 DO
  1266.       IF skipTab[ORD(FindStr[j])] = flen THEN
  1267.         skipTab[ORD(FindStr[j])] := i;
  1268.       END;
  1269.       INC(i);
  1270.     END;
  1271.   END CalcSkipTab;
  1272.  
  1273.  
  1274.   PROCEDURE Search(): BOOLEAN;
  1275.   (* Searches string and hilites it if found. Result is TRUE if string found *)
  1276.  
  1277.   VAR ch: CHAR;
  1278.       i,j,t: INTEGER;
  1279.  
  1280.   BEGIN
  1281.     IF flen > BottomLine.size THEN RETURN f END;
  1282.     i := flen-1;
  1283.     FOR j := flen-1 TO 0 BY -1 DO
  1284.       LOOP
  1285.         ch := BottomLine.text[i];
  1286.         CASE ch OF "a".."z","à".."ö","ø".."þ": DEC(ch,caseDelta) ELSE END;
  1287.         IF ch = FindStr[j] THEN EXIT END;
  1288.         t := skipTab[ORD(ch)];
  1289.         IF flen-j > t THEN INC(i,flen-j) ELSE INC(i,t) END;
  1290.         IF i >= BottomLine.size THEN RETURN f END;
  1291.         j := flen-1;
  1292.       END;
  1293.       DEC(i);
  1294.     END;
  1295.     INC(i); IF i<0 THEN RETURN f END;
  1296.     SYS.SETREG(0,TryBottomnext());
  1297.     FindLine := BottomLine;
  1298.     HiLite(i,flen);
  1299.     found := w; RETURN w;
  1300.   END Search;
  1301.  
  1302.  
  1303.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1304.   VAR IStr : String;
  1305.       fmt  : StringPtr;
  1306.       i    : INTEGER;
  1307.       data : STRUCT name : e.STRPTR;
  1308.                     perc : LONGINT;
  1309.                     tlen : LONGINT;
  1310.                     flen : LONGINT;
  1311.                     lins : LONGINT;
  1312.              END;
  1313.   BEGIN
  1314.     data.name := SYS.ADR(OldName);
  1315.     data.perc := TextLength * 100 DIV FileLength;
  1316.     data.tlen := TextLength;
  1317.     data.flen := FileLength;
  1318.     data.lins := AnzLines-1;
  1319.     fmt := LocStr(MSGINFOFMT);
  1320.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1321.     IStr[0] := 7X; IF depth<2 THEN IStr[0] := 2X END;
  1322.     i := SHORT(str.Length(IStr));
  1323.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1324.     IStr[i] := 0X;
  1325.     CopyToWriteText(SYS.ADR(IStr));
  1326.     AddBottomLine(SYS.ADR(writeText),Fast);
  1327.     Info := w;
  1328.     Scroll := f;
  1329.   END ShowInfo;
  1330.  
  1331.  
  1332.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1333.  
  1334.   CONST
  1335.     num = 25;
  1336.  
  1337.   VAR
  1338.     i,j  : INTEGER;
  1339.     help : ARRAY num OF StringPtr;
  1340.     fmt  : StringPtr;
  1341.     data : StringPtr;
  1342.     h1   : String;
  1343.  
  1344.   BEGIN
  1345.     data := SYS.ADR(Version);
  1346.     fmt := LocStr(MSGH1);
  1347.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(h1));
  1348.     help[ 0] := SYS.ADR(h1);
  1349.     help[ 1] := SYS.ADR("");
  1350.     help[ 2] := LocStr(MSGH2);
  1351.     help[ 3] := LocStr(MSGH3);
  1352.     help[ 4] := LocStr(MSGH4);
  1353.     help[ 5] := LocStr(MSGH5);
  1354.     help[ 6] := LocStr(MSGH6);
  1355.     help[ 7] := LocStr(MSGH7);
  1356.     help[ 8] := LocStr(MSGH8);
  1357.     help[ 9] := LocStr(MSGH9);
  1358.     help[10] := LocStr(MSGH10);
  1359.     help[11] := LocStr(MSGH11);
  1360.     help[12] := LocStr(MSGH12);
  1361.     help[13] := LocStr(MSGH13);
  1362.     help[14] := LocStr(MSGH24);
  1363.     help[15] := LocStr(MSGH14);
  1364.     help[16] := LocStr(MSGH23);
  1365.     help[17] := LocStr(MSGH15);
  1366.     help[18] := LocStr(MSGH16);
  1367.     help[19] := LocStr(MSGH17);
  1368.     help[20] := LocStr(MSGH18);
  1369.     help[21] := SYS.ADR("");
  1370.     help[22] := LocStr(MSGH19);
  1371.     help[23] := LocStr(MSGH21);
  1372.     help[24] := LocStr(MSGH22);
  1373.     ClearDisplay();
  1374.     j := (NumLines - num) DIV 2; IF j<0 THEN j:=0 END;
  1375.     i := 0;
  1376.     WHILE (i<num) & (i+j<NumLines) DO
  1377.       WriteTo(help[i],j+i);
  1378.       INC(i);
  1379.     END;
  1380.     LOOP
  1381.       e.WaitPort(Window.userPort);
  1382.       MyMsgPtr := e.GetMsg(Window.userPort);
  1383.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1384.       e.ReplyMsg(MyMsgPtr);
  1385.     END;
  1386.     e.ReplyMsg(MyMsgPtr);
  1387.     BottomLine := TopLine;
  1388.     NewDisplay
  1389.   END Help;
  1390.  
  1391.  
  1392.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1393.  
  1394.   BEGIN
  1395.     WaitAllRead;
  1396.     BottomLine := LastLine;
  1397.     NewDisplay
  1398.   END Bottom;
  1399.  
  1400.  
  1401.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1402.   (* IF result=w THEN EXIT END *)
  1403.  
  1404.   BEGIN
  1405.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1406.       IF wasInfo THEN RETURN w END;
  1407.       ShowInfo(Shift);
  1408.     ELSE
  1409.       IF Down THEN
  1410.         Scroll := ~Scroll;
  1411.         IF ~Scroll THEN ShowInfo(Fast) END;
  1412.       ELSE
  1413.         Down := w;
  1414.         Scroll := w;
  1415.       END;
  1416.       Fast := Shift;
  1417.     END;
  1418.     RETURN f;
  1419.   END Space;
  1420.  
  1421.  
  1422.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1423.  
  1424.   BEGIN
  1425.     Fast := Shift;
  1426.     Scroll := Down OR ~Scroll;
  1427.     Down := f
  1428.   END BackSpace;
  1429.  
  1430.  
  1431. BEGIN
  1432.   (* $IF SmallData *)
  1433.   SYS.SETREG(13,e.AbsExecBase.thisTask.userData);
  1434.   (* $END *)
  1435.  
  1436.   (* $IFNOT ClearVars *)
  1437.   Find[0] := 0X; FindStr[0] := 0X; Goto[0] := 0X;
  1438.   (* $END *)
  1439.  
  1440.   Down := w;
  1441.  
  1442.   SYS.SETREG(0,e.Wait(mySig));
  1443.  
  1444.   LOOP
  1445.  
  1446.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1447.  
  1448. (*------  Type Text:  ------*)
  1449.  
  1450.     LOOP
  1451.       IF Scroll THEN
  1452.         IF Down THEN
  1453.           ScrollDown(Fast);
  1454.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1455.         ELSE
  1456.           ScrollUp(Fast);
  1457.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1458.         END;
  1459.       ELSE
  1460.         MakeScroll(f,f,w);
  1461.         e.WaitPort(Window.userPort);
  1462.       END;
  1463.  
  1464.       MyMsgPtr := e.GetMsg(Window.userPort);
  1465.  
  1466.       IF (MyMsgPtr#NIL) THEN
  1467.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1468.         e.ReplyMsg(MyMsgPtr);
  1469.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1470.         e.WaitPort(Window.userPort);
  1471.         I.OldModifyIDCMP(Window,MyIdcmp);
  1472.       END;
  1473.     END;
  1474.  
  1475.     Code      := MyMsgPtr.code;
  1476.     Class     := MyMsgPtr.class;
  1477.     Qualifier := MyMsgPtr.qualifier;
  1478.  
  1479.     e.ReplyMsg(MyMsgPtr);
  1480.  
  1481.  
  1482.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * Qualifier # {};
  1483.     Alt   := {ie.lAlt  ,ie.rAlt}               * Qualifier # {};
  1484.     Sync  := ~ (ie.control IN Qualifier);
  1485.  
  1486.     IF ~Sync THEN Shift := w END;
  1487.  
  1488.  
  1489.     IF (I.rawKey       IN Class) & (Code<80H) OR
  1490.        (I.mouseButtons IN Class) & ({ie.leftButton,ie.rightButton}*Qualifier#{})
  1491.     THEN
  1492.       wasInfo := f;
  1493.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1494.     END;
  1495.  
  1496.  
  1497.     IF I.mouseButtons IN Class THEN
  1498.  
  1499.       IF    (ie.leftButton IN Qualifier)   & Space()   THEN EXIT
  1500.       ELSIF ie.rightButton IN Qualifier THEN BackSpace END;
  1501.  
  1502.     ELSIF (I.closeWindow IN Class) THEN
  1503.       EXIT;
  1504.  
  1505.     ELSIF (I.rawKey IN Class) & (Code<80H) THEN
  1506.  
  1507.       CASE Code OF
  1508.  
  1509.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1510.  
  1511.       | BS:    BackSpace                                    (* BackSpace *)
  1512.  
  1513.       | DOWN,NK2,NK3:                                       (* Down *)
  1514.  
  1515.           IF (MyFile=NIL) & (BottomLine.next=NIL) THEN
  1516.             I.DisplayBeep(NIL)
  1517.           ELSE
  1518.             IF Shift & (Code # NK3) THEN
  1519.               Scroll := ~Down OR ~Scroll OR ~Fast;
  1520.               Fast := w; Down := w;
  1521.             ELSE
  1522.               IF Alt OR (Code=NK3) THEN
  1523.                 IF oldstyle THEN
  1524.                   i := NumLines-1;
  1525.                   REPEAT
  1526.                     ScrollDown(w);
  1527.                     DEC(i);
  1528.                   UNTIL i=0;
  1529.                 ELSE
  1530.                   IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1531.                   NewDisplay;
  1532.                 END;
  1533.               ELSE
  1534.                 ScrollDown(w);
  1535.               END;
  1536.               Scroll := f;
  1537.             END;
  1538.           END;
  1539.  
  1540.       | UP,NK8,NK9:                                        (* Up *)
  1541.  
  1542.           IF (TopLine.prev=NIL) OR (TopLine.prev.prev=NIL) THEN
  1543.             I.DisplayBeep(NIL)
  1544.           ELSE
  1545.             IF Shift & (Code # NK9) THEN
  1546.               Scroll := Down OR ~Scroll OR ~Fast;
  1547.               Fast := w; Down := f;
  1548.             ELSE
  1549.               IF Alt OR (Code=NK9) THEN
  1550.                 i := NumLines-1;
  1551.                 IF oldstyle THEN
  1552.                   REPEAT
  1553.                     ScrollUp(w);
  1554.                     DEC(i);
  1555.                   UNTIL i=0;
  1556.                 ELSE
  1557.                   (*IF TopLine.prev#NIL THEN*)
  1558.                   BottomLine := TopLine;
  1559.                   WHILE (i>0) & (BottomLine.prev#NIL) DO
  1560.                     BottomLine := BottomLine.prev;
  1561.                     DEC(i);
  1562.                   END;
  1563.                   NewDisplay;
  1564.                   (*END;*)
  1565.                 END;
  1566.               ELSE
  1567.                 ScrollUp(w);
  1568.               END;
  1569.               Scroll := f;
  1570.             END;
  1571.           END;
  1572.  
  1573.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1574.  
  1575.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1576.  
  1577.       | NK1: Bottom                                        (* End *)
  1578.  
  1579.       | F1..F10:                                           (* F1..F10 *)
  1580.  
  1581.           i := Code-F1;
  1582.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1583.             BottomLine := TextMarkers[i];
  1584.             NewDisplay;
  1585.           ELSE
  1586.             TextMarkers[i] := TopLine;
  1587.           END
  1588.  
  1589.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1590.  
  1591.       | HELP: Help                                         (* Help *)
  1592.  
  1593.       | ESC:  EXIT                                         (* Quit *)
  1594.  
  1595.       | NK5:  IF wasInfo THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1596.  
  1597.       ELSE
  1598.  
  1599.         IF Code<40H THEN         (* examine vanilla keycode: *)
  1600.  
  1601.           chr := KeyMap[Code];
  1602.  
  1603.           CASE chr OF
  1604.  
  1605.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1606.  
  1607.           | "b": Bottom;                                   (* End *)
  1608.  
  1609.           | "f","n","p":                                   (* Find, Next, Previous *)
  1610.  
  1611.             IF chr="f" THEN
  1612.               caseDelta := 32; IF Shift THEN caseDelta := 0 END;
  1613.               GetString(Find,f,w);
  1614.               FindLine := NIL; flen := 0;
  1615.               LOOP
  1616.                 FindStr[flen] := Find[flen];
  1617.                 CASE FindStr[flen] OF
  1618.                   "a".."z","à".."ö","ø".."þ": DEC(FindStr[flen],caseDelta) |
  1619.                   0X: EXIT;
  1620.                 ELSE
  1621.                 END;
  1622.                 INC(flen);
  1623.               END;
  1624.               CalcSkipTab;
  1625.             END;
  1626.             found := f;
  1627.             IF FindStr[0]#0X THEN
  1628.               Busy;
  1629.               i := NumLines;
  1630.               IF FindLine # NIL THEN FindLine := FindLine.next END;
  1631.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1632.                 BottomLine := BottomLine.prev; DEC(i);
  1633.               END;
  1634.               IF (BottomLine # FindLine) OR (BottomLine=NIL) THEN
  1635.                 BottomLine := TopLine
  1636.               END;
  1637.               IF chr # "p" THEN                          (* next *)
  1638.                 WHILE (BottomLine # NIL) & ~ Search() DO
  1639.                   SYS.SETREG(0,TryBottomnext());
  1640.                   BottomLine := BottomLine.next;
  1641.                 END;
  1642.               ELSE                                       (* previous *)
  1643.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1644.                 REPEAT
  1645.                   BottomLine := BottomLine.prev
  1646.                 UNTIL (BottomLine=NIL) OR Search();
  1647.               END;
  1648.               IF BottomLine#NIL THEN
  1649.                 li := NumLines DIV 2;
  1650.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1651.               END;
  1652.               UnBusy;
  1653.             END;
  1654.  
  1655.             IF ~ found THEN
  1656.               I.DisplayBeep(NIL);
  1657.               BottomLine := TopLine;
  1658.             END;
  1659.             NewDisplay;
  1660.             IF found THEN UnHiLite END;
  1661.  
  1662.           | "w","c":                                       (* write block *)
  1663.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~print & ~save THEN
  1664.               savefrom := 0; savesize := 0;
  1665.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1666.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1667.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1668.               DEC(savesize,savefrom);
  1669.               IF savesize>0 THEN
  1670.                 IF chr="c" THEN copy := w ELSE
  1671.                   GetString(WriteName,f,w);
  1672.                   copy := f;
  1673.                 END;
  1674.                 WaitAllRead; save := w; e.Signal(SYS.ADR(Me.task),mySig);
  1675.               END
  1676.             END
  1677.  
  1678.           | "o","e":                                       (* Print, Edit *)
  1679.  
  1680.             IF Shift & Alt & ~print & ~save THEN
  1681.               nameptr := SYS.ADR(Name);
  1682.               IF chr="o" THEN
  1683.                 e.OldRawDoFmt('Type "%s" to PRT:',SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1684.               ELSE
  1685.                 e.OldRawDoFmt(editcmd,SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1686.               END;
  1687.               WaitAllRead; print := w; e.Signal(SYS.ADR(Me.task),mySig);
  1688.             END
  1689.  
  1690.           | "l":                                           (* Load Text *)
  1691.  
  1692.             ClearDisplay;
  1693.             NewText := w; e.Signal(SYS.ADR(Me.task),mySig);
  1694.             REPEAT UNTIL (mySigBit IN e.Wait(mySig)) & ~ NewText |
  1695.  
  1696.           | "g":                                           (* goto *)
  1697.  
  1698.             GetString(Goto,w,w);
  1699.             li := SHORT(StrInfo.longInt);
  1700.             Busy;
  1701.             BottomLine := FirstLine;
  1702.             WHILE (li >= 0) & TryBottomnext() DO
  1703.               BottomLine := BottomLine.next;
  1704.               DEC(li)
  1705.             END;
  1706.             UnBusy;
  1707.             NewDisplay
  1708.  
  1709.           | "h":     Help                                  (* Help *)
  1710.  
  1711.           | "q","x": IF wasInfo THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1712.  
  1713.           ELSE END;
  1714.  
  1715.         END;   (* IF Code<40H THEN *)
  1716.  
  1717.       END;   (* CASE Code OF *)
  1718.  
  1719.     END;   (* IF I.rawKey IN Class THEN *)
  1720.  
  1721.   END;   (* LOOP *)
  1722.  
  1723.   Done := w;
  1724.   e.Signal(SYS.ADR(Me.task),mySig);
  1725.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1726.  
  1727. END ShowProc;
  1728.  
  1729. (* $Debug= *)
  1730.  
  1731.  
  1732. (*--------------------------  File Requester:  ----------------------------*)
  1733.  
  1734.  
  1735. PROCEDURE FileReq(VAR Name: String);
  1736.  
  1737. CONST
  1738.   dummy     = u.user + 80000H;
  1739.   taghail   = dummy + 1;
  1740.   window    = dummy + 2;
  1741.   leftEdge  = dummy + 3;         (* Initialize LeftEdge                  *)
  1742.   topEdge   = dummy + 4;         (* Initialize TopEdge                   *)
  1743.   width     = dummy + 5;
  1744.   height    = dummy + 6;
  1745.   hookFunc  = dummy + 7;         (* Hook function pointer                *)
  1746.   file      = dummy + 8;         (* Initial name of file follows         *)
  1747.   dir       = dummy + 9;         (* Initial string for filerequest dir   *)
  1748.   pattern   = dummy + 10;
  1749.   funcFlags = dummy + 20;
  1750.   fiDir     = u.user + 50;
  1751.   longPath  = 0;
  1752.   patGad    = 0;
  1753.  
  1754. TYPE
  1755.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  1756.  
  1757.   FileRequester = STRUCT
  1758.                     hail      : StringPtr;
  1759.                     ddef      : StringPtr;
  1760.                     ddir      : StringPtr;
  1761.                     wind      : I.WindowPtr;
  1762.                     funcFlags : SHORTSET;
  1763.                     flags2    : SHORTSET;
  1764.                     function  : PROCEDURE;
  1765.                     reserved2 : LONGINT;
  1766.                   END;
  1767. VAR
  1768.   fr: FileRequesterPtr;
  1769.   pscr: I.ScreenPtr;
  1770.   i,j: INTEGER;
  1771.   res: BOOLEAN;
  1772.  
  1773.   PROCEDURE AllocAslRequest  {asl,-48} (type{0}: LONGINT; tag{8}..: e.APTR): FileRequesterPtr;
  1774.   PROCEDURE FreeAslRequest   {asl,-54} (fr{8}: FileRequesterPtr);
  1775.   PROCEDURE RequestFile      {asl,-42} (fr{8}: FileRequesterPtr): e.APTR;
  1776.  
  1777. BEGIN
  1778.   j := SHORT(str.Length(Name));
  1779.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  1780.   IF j=0 THEN j := -1 END;
  1781.   i := 0;
  1782.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  1783.   j := 0;
  1784.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  1785.  
  1786.   pscr := I.LockPubScreen(NIL);
  1787.   IF pscr#NIL THEN
  1788.     I.ScreenToFront(pscr);
  1789.     I.UnlockPubScreen(NIL,pscr);
  1790.   END;
  1791.  
  1792.   IF asl=NIL THEN asl := e.OpenLibrary("asl.library",36) END;
  1793.   IF asl#NIL THEN
  1794.     fr := AllocAslRequest(0,taghail, SYS.ADR(MuchText),
  1795.                             file,    SYS.ADR(Filename),
  1796.                             dir,     SYS.ADR(Dirname),
  1797.                             pattern, SYS.ADR(Pattern),
  1798.                             funcFlags,ASH(1,patGad),
  1799.                             u.done);
  1800.     IF fr=NIL THEN Request(LocStr(MSGOOM)^) END;
  1801.     res := RequestFile(fr)#NIL;
  1802.     IF res THEN
  1803.       Filename := fr.ddef^;
  1804.       Dirname  := fr.ddir^;
  1805.     END;
  1806.     FreeAslRequest(fr);
  1807.     IF ~res THEN HALT(d.ok) END;
  1808.   ELSE
  1809.     Request("Can't open asl.library")
  1810.   END;
  1811.   Name := Dirname;
  1812.   i := SHORT(str.Length(Name));
  1813.   IF (i>0) THEN
  1814.     CASE Name[i-1] OF "/",":": ELSE
  1815.       Name[i] := "/"; INC(i);
  1816.     END;
  1817.   END;
  1818.   j := 0;
  1819.   LOOP
  1820.     Name[i] := Filename[j];
  1821.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  1822.     INC(i);
  1823.     INC(j);
  1824.   END;
  1825.   Name[i] := 0X;
  1826.   IF Screen#NIL THEN I.ScreenToFront(Screen) END;
  1827.   IF Window#NIL THEN I.ActivateWindow(Window) END;
  1828. END FileReq;
  1829.  
  1830.  
  1831. (*--------------------------  Decrunch:  ----------------------------*)
  1832.  
  1833.  
  1834. PROCEDURE DirExists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  1835. VAR lock: d.FileLockPtr;
  1836.     result: BOOLEAN;
  1837.     oldwp: e.APTR;
  1838. BEGIN
  1839.   result := f;
  1840.   oldwp := Me.windowPtr;
  1841.   Me.windowPtr := -1;
  1842.   lock := d.Lock(name,d.sharedLock);
  1843.   IF lock # NIL THEN
  1844.     result := w;
  1845.     d.UnLock(lock)
  1846.   END;
  1847.   Me.windowPtr := oldwp;
  1848.   RETURN result
  1849. END DirExists;
  1850.  
  1851.  
  1852. PROCEDURE Decrunch;
  1853.  
  1854. CONST
  1855.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  1856.   inName     = tagBase+01H;
  1857.   inFH       = tagBase+02H;
  1858.   outName    = tagBase+10H;
  1859.   password   = tagBase+24H;
  1860.   getError   = tagBase+25H;
  1861.   shortError = tagBase+31H;
  1862.   typePacked = 1;
  1863.   flagsPassword = 0;
  1864.  
  1865. TYPE
  1866.   XpkFib = STRUCT
  1867.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  1868.     uLen       : LONGINT;
  1869.     cLen       : LONGINT;
  1870.     nLen       : LONGINT;
  1871.     uCur       : LONGINT;
  1872.     cCur       : LONGINT;
  1873.     id         : LONGINT;
  1874.     packer     : ARRAY 6 OF CHAR;
  1875.     subVersion : INTEGER;
  1876.     masVersion : INTEGER;
  1877.     flags      : LONGSET;
  1878.     head       : ARRAY 16 OF CHAR;
  1879.     ratio      : LONGINT;
  1880.     reserved   : ARRAY 8 OF LONGINT;
  1881.   END;
  1882.  
  1883. VAR
  1884.   file: d.FileHandlePtr;
  1885.   err: LONGINT;
  1886.   xpkFib: XpkFib;
  1887.   errBuf: ARRAY 81 OF CHAR;
  1888.  
  1889.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  1890.                                   tag1{9}..   : e.APTR): LONGINT;
  1891.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  1892.  
  1893. BEGIN
  1894.   Decrunched := f;
  1895.   OldName := Name;
  1896.  
  1897.   IF DirExists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  1898.  
  1899.   e.OldRawDoFmt("Decrunched.%lx",SYS.ADR(meInt),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  1900.  
  1901.   IF xpk=NIL THEN
  1902.     xpk := e.OpenLibrary("xpkmaster.library",1);
  1903.   END;
  1904.   IF xpk#NIL THEN
  1905.     err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  1906.     IF (err#0) & (err#-20) THEN
  1907.       Request(LocStr(MSGOOM)^)
  1908.     END;
  1909.     IF (err=-20) OR (xpkFib.type#typePacked) THEN
  1910.       Name := OldName;
  1911.       RETURN
  1912.     END;
  1913.     IF flagsPassword IN xpkFib.flags THEN GetString(Password,f,f) END;
  1914.     Busy;
  1915.     err := UnpackTags(inFH,       SYS.VAL(LONGINT,MyFile),
  1916.                       outName,    SYS.ADR(Name),
  1917.                       password,   SYS.ADR(Password),
  1918.                       getError,   SYS.ADR(errBuf),
  1919.                       shortError, e.true,
  1920.                       u.done);
  1921.     UnBusy;
  1922.     IF err#0 THEN Request(errBuf) END;
  1923.     file := d.Open(Name,d.oldFile);
  1924.     IF file#NIL THEN
  1925.       Decrunched := w;
  1926.       d.OldClose(MyFile);
  1927.       MyFile := file;
  1928.       RETURN
  1929.     ELSE
  1930.       Request(LocStr(MSGCOF)^);
  1931.     END;
  1932.   END;
  1933.   Name := OldName;
  1934. END Decrunch;
  1935.  
  1936.  
  1937. (*-----------------  Screen Mode Requester:  ------------------------*)
  1938.  
  1939.  
  1940. PROCEDURE GetNode (VAR list: e.List; index: LONGINT): e.NodePtr;
  1941.   VAR n: e.NodePtr;
  1942. BEGIN
  1943.   n := list.head;
  1944.   WHILE index > 0 DO
  1945.     IF n.succ=NIL THEN RETURN NIL END;
  1946.     n := n.succ;
  1947.     DEC(index);
  1948.   END;
  1949.   RETURN n;
  1950. END GetNode;
  1951.  
  1952.  
  1953. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): INTEGER;
  1954. CONST
  1955.   gadLISTVIEW    = 1;
  1956.   gadBUTTONSave  = 2;
  1957.   gadBUTTONUse   = 3;
  1958.   gadBUTTONCancel= 4;
  1959.  
  1960.   Topaz80 = g.TextAttr(SYS.ADR("topaz.font"), 8, SHORTSET{}, SHORTSET{});
  1961.  
  1962. TYPE
  1963.   MyNodePtr = UNTRACED POINTER TO MyNode;
  1964.   MyNode = STRUCT (node: e.Node)
  1965.              displayID: LONGINT;
  1966.            END;
  1967.  
  1968. VAR
  1969.   ng            : gt.NewGadget;
  1970.   gad,glist     : I.GadgetPtr;
  1971.   Win           : I.WindowPtr;
  1972.   pub           : I.ScreenPtr;
  1973.   font          : g.TextAttrPtr;
  1974.   width,height  : INTEGER;
  1975.   txW,txH       : INTEGER;
  1976.   result,index  : INTEGER;
  1977.   firstindex    : INTEGER;
  1978.   topborder     : INTEGER;
  1979.   x1,x2,min     : INTEGER;
  1980.   terminated    : BOOLEAN;
  1981.   lvlist        : e.List;
  1982.   lvSelectedTag : LONGINT;
  1983.   vi            : e.APTR;
  1984.   imsg          : I.IntuiMessagePtr;
  1985.   node          : MyNodePtr;
  1986.   dispID        : LONGINT;
  1987.   displayInfo   : g.DisplayInfo;
  1988.   nameInfo      : g.NameInfo;
  1989.  
  1990.  
  1991.   PROCEDURE StrLen (str: e.STRPTR; min: INTEGER): INTEGER;
  1992.   VAR it: I.IntuiText;
  1993.       len: INTEGER;
  1994.   BEGIN
  1995.     (* $IFNOT ClearVars *)
  1996.     len := 0;
  1997.     it.leftEdge := 0; it.topEdge  := 0; it.frontPen := 0; it.backPen  := 0;
  1998.     it.drawMode := SHORTSET{}; it.nextText := NIL;
  1999.     (* $END *)
  2000.     IF str#NIL THEN
  2001.       it.iTextFont := font; it.iText := str;
  2002.       len := I.IntuiTextLength(it);
  2003.     END;
  2004.     IF len > min THEN RETURN len ELSE RETURN min END;
  2005.   END StrLen;
  2006.  
  2007. BEGIN
  2008.   (* $IFNOT ClearVars *)
  2009.   Win := NIL; vi := NIL; glist := NIL; pub := NIL; result := 0;
  2010.   (* $END *)
  2011.  
  2012.   LOOP
  2013.     pub := I.LockPubScreen(NIL);         IF pub=NIL THEN EXIT END;
  2014.     vi  := gt.GetVisualInfo(pub,u.done); IF vi =NIL THEN EXIT END;
  2015.     topborder := pub.wBorTop + pub.font.ySize + 1;
  2016.  
  2017.     font := pub.font;
  2018.     txW := pub.rastPort.txWidth; txH := pub.rastPort.txHeight;
  2019.     width := txW * 36 + 16; height := txH * 8 + 32;
  2020.     IF ((width+pub.wBorLeft+pub.wBorRight) > pub.width) OR ((height+topborder+pub.wBorBottom) > pub.height) THEN
  2021.       font := SYS.ADR(Topaz80);
  2022.       txW := 8; txH := 8;
  2023.       width := 8 * 36 + 16; height := 8 * 8 + 32;
  2024.     END;
  2025.     min := txW * 6;
  2026.  
  2027.     gad := gt.CreateContext(glist);
  2028.  
  2029.     ng.textAttr := font;
  2030.     ng.visualInfo := vi;
  2031.     ng.userData := NIL;
  2032.  
  2033.     ng.leftEdge := 16;
  2034.     ng.height := txH+4;
  2035.     ng.topEdge := topborder+height-ng.height-5;
  2036.     ng.gadgetText := LocStr(MSGSAVE);
  2037.     ng.width := StrLen(ng.gadgetText,min)+8;
  2038.     ng.gadgetID := gadBUTTONSave;
  2039.     ng.flags := LONGSET{};
  2040.     x1 := ng.leftEdge+ng.width;
  2041.  
  2042.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2043.  
  2044.     ng.gadgetText := LocStr(MSGCANCEL);
  2045.     ng.width := StrLen(ng.gadgetText,min)+8;
  2046.     ng.leftEdge := width-ng.width-8;
  2047.     ng.gadgetID := gadBUTTONCancel;
  2048.     x2 := ng.leftEdge;
  2049.  
  2050.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2051.  
  2052.     ng.gadgetText := LocStr(MSGUSE);
  2053.     ng.width := StrLen(ng.gadgetText,min)+8;
  2054.     ng.leftEdge := (x1+x2-ng.width) DIV 2;
  2055.     ng.gadgetID := gadBUTTONUse;
  2056.  
  2057.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2058.  
  2059.     lvlist.head := SYS.ADR(lvlist.tail);
  2060.     lvlist.tail := NIL;
  2061.     lvlist.tailPred := SYS.ADR(lvlist.head);
  2062.  
  2063.     index := 0;
  2064.     firstindex := -1;
  2065.     dispID := g.NextDisplayInfo(g.invalidID);
  2066.  
  2067.     WHILE dispID # g.invalidID DO
  2068.       IF (g.GetDisplayInfoData(NIL,displayInfo,SIZE(displayInfo),g.dtagDisp,dispID) > 0) &
  2069.          (displayInfo.notAvailable = 0) &
  2070.          (LONGSET{g.isHAM,g.isExtraHalfBrite,g.isDualPF} * displayInfo.propertyFlags = LONGSET{}) &
  2071.          (g.GetDisplayInfoData(NIL,nameInfo,SIZE(nameInfo),g.dtagName,dispID) > 0)
  2072.       THEN
  2073.         SYS.ALLOCATE(node);
  2074.         IF node # NIL THEN
  2075.           SYS.ALLOCATE(node.node.name);
  2076.           IF node.node.name # NIL THEN
  2077.             COPY(nameInfo.name,node.node.name^);
  2078.             node.displayID := dispID;
  2079.             e.AddTail(lvlist, node);
  2080.             IF dispID=displayID THEN firstindex := index END;
  2081.             INC(index);
  2082.           ELSE
  2083.             EXIT
  2084.           END;
  2085.         ELSE
  2086.           EXIT
  2087.         END;
  2088.       END;
  2089.       dispID := g.NextDisplayInfo(dispID);
  2090.     END;
  2091.  
  2092.     ng.leftEdge := 16;
  2093.     ng.topEdge := txH+8+topborder;
  2094.     ng.width := width-25;
  2095.     ng.height := txH*6+15;
  2096.     ng.gadgetText := LocStr(MSGCHOOSESM);
  2097.     ng.gadgetID := gadLISTVIEW;
  2098.     ng.flags := LONGSET{gt.highLabel,gt.placeTextAbove};
  2099.  
  2100.     IF firstindex >= 0 THEN lvSelectedTag := gt.lvSelected
  2101.                        ELSE lvSelectedTag := u.ignore END;
  2102.  
  2103.     gad := gt.CreateGadget(gt.listViewKind, gad, ng,
  2104.                     gt.lvLabels,       SYS.ADR(lvlist),
  2105.                     gt.lvShowSelected, NIL,
  2106.                     gt.lvScrollWidth,  txW*2,
  2107.                     I.layoutaSpacing,  2,
  2108.                     lvSelectedTag,     firstindex,
  2109.                     u.done);
  2110.     IF gad = NIL THEN EXIT END;
  2111.  
  2112.     Win := I.OpenWindowTagsA(NIL,
  2113.                              I.waLeft,        30,
  2114.                              I.waTop,         20,
  2115.                              I.waInnerWidth,  width,
  2116.                              I.waInnerHeight, height,
  2117.                              I.waTitle,       SYS.ADR(MuchText),
  2118.                              I.waFlags,       LONGSET{I.activate,I.windowDrag,I.windowDepth,I.simpleRefresh,I.rmbTrap},
  2119.                              I.waIDCMP,       gt.listViewIDCMP+gt.buttonIDCMP+LONGSET{I.gadgetUp,I.refreshWindow},
  2120.                              I.waCustomScreen,pub,
  2121.                              I.waGadgets,     glist,
  2122.                              u.done);
  2123.     IF Win = NIL THEN EXIT END;
  2124.     gt.RefreshWindow(Win, NIL);
  2125.  
  2126.     dispID := displayID;
  2127.     terminated := f;
  2128.  
  2129.     WHILE ~terminated DO
  2130.       e.WaitPort(Win.userPort);
  2131.       LOOP
  2132.         IF terminated THEN EXIT END;
  2133.         imsg := gt.GetIMsg(Win.userPort);
  2134.         IF imsg=NIL THEN EXIT END;
  2135.         gad := imsg.iAddress;
  2136.   
  2137.         IF I.gadgetUp IN imsg.class THEN
  2138.           CASE gad.gadgetID OF
  2139.           | gadBUTTONSave:   result := 1; displayID := dispID; terminated := w;
  2140.           | gadBUTTONUse:    result := 2; displayID := dispID; terminated := w;
  2141.           | gadBUTTONCancel: terminated := w;
  2142.           | gadLISTVIEW:     node := GetNode(lvlist,imsg.code);
  2143.                              IF node # NIL THEN dispID := node.displayID END;
  2144.           ELSE
  2145.           END;
  2146.         END;
  2147.  
  2148.         IF I.refreshWindow IN imsg.class THEN
  2149.           gt.BeginRefresh(Win);
  2150.           gt.EndRefresh(Win, I.LTRUE);
  2151.         END;
  2152.  
  2153.         gt.ReplyIMsg(imsg);
  2154.   
  2155.       END;
  2156.     END;
  2157.  
  2158.     EXIT
  2159.   END;
  2160.  
  2161.   IF Win   # NIL THEN I.CloseWindow(Win) END;
  2162.   IF glist # NIL THEN gt.FreeGadgets(glist) END;
  2163.   IF vi    # NIL THEN gt.FreeVisualInfo(vi) END;
  2164.   IF pub   # NIL THEN I.UnlockPubScreen(NIL,pub) END;
  2165.  
  2166.   RETURN result;
  2167. END ScreenModeReq;
  2168.  
  2169.  
  2170. (*-------------------------------------------------------------------------*)
  2171.  
  2172.  
  2173. PROCEDURE SavePrefs;
  2174.  
  2175.   PROCEDURE SavePrefsName(name: StringPtr);
  2176.   VAR file: d.FileHandlePtr;
  2177.       l: LONGINT;
  2178.   BEGIN
  2179.     file := d.Open(name^,d.newFile);
  2180.     IF file # NIL THEN
  2181.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2182.       l := 16;
  2183.       SYS.SETREG(0,d.Write(file,l,4));
  2184.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2185.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2186.       l := 4;
  2187.       SYS.SETREG(0,d.Write(file,l,4));
  2188.       SYS.SETREG(0,d.Write(file,id,4));
  2189.       d.OldClose(file);
  2190.     END;
  2191.   END SavePrefsName;
  2192.  
  2193. BEGIN
  2194.   IF DirExists("ENV:") THEN
  2195.     SavePrefsName(SYS.ADR("ENV:MuchMore.prefs"))
  2196.   END;
  2197.   IF DirExists("ENVARC:") THEN
  2198.     SavePrefsName(SYS.ADR("ENVARC:MuchMore.prefs"))
  2199.   END;
  2200. END SavePrefs;
  2201.  
  2202.  
  2203. (*-------------------------------------------------------------------------*)
  2204.  
  2205.  
  2206. PROCEDURE LoadPrefs;
  2207.  
  2208. VAR file: d.FileHandlePtr;
  2209.     l,i,s: LONGINT;
  2210.     buf: ARRAY 80 OF CHAR;
  2211.     ok: BOOLEAN;
  2212.  
  2213. BEGIN
  2214.   file := NIL;
  2215.   IF DirExists("PROGDIR:") THEN
  2216.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2217.   END;
  2218.   IF (file=NIL) & DirExists("ENV:") THEN
  2219.     file := d.Open("ENV:MuchMore.prefs",d.oldFile);
  2220.   END;
  2221.   IF file # NIL THEN
  2222.     LOOP
  2223.       IF (d.Read(file,i,4) <= 0)        OR
  2224.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2225.          (d.Read(file,s,4) <= 0)        OR
  2226.          (d.Read(file,i,4) <= 0)        OR
  2227.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2228.       WHILE w DO
  2229.         IF (d.Read(file,i,4) <= 0)      OR
  2230.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2231.         IF ODD(s) THEN INC(s) END;
  2232.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2233.           SYS.SETREG(0,d.Read(file,id,4));
  2234.         ELSE
  2235.           IF s < 0 THEN EXIT END;
  2236.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2237.         END;
  2238.       END;
  2239.  
  2240.       EXIT;
  2241.     END;
  2242.     d.OldClose(file);
  2243.   END;
  2244.   IF (d.GetVar("EDITOR",buf,SIZE(buf),LONGSET{})>0) THEN
  2245.     COPY(buf,editcmd);
  2246.   END;
  2247. END LoadPrefs;
  2248.  
  2249.  
  2250. (*------------------------  Get Tooltypes:  --------------------------*)
  2251.  
  2252.  
  2253. PROCEDURE ParseIcon(icon: DiskObjectPtr);
  2254. VAR tt: StringPtr;
  2255.  
  2256. BEGIN
  2257.   IF icon # NIL THEN
  2258.     tt := FindToolType(icon.toolTypes,"PALETTE");    IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2259.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2260.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2261.     tt := FindToolType(icon.toolTypes,"EDITOR");     IF (tt # NIL) THEN COPY(tt^,editcmd) END;
  2262.     tt := FindToolType(icon.toolTypes,"OLDSTYLE");   IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN oldstyle := w END;
  2263.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN depth := SHORT(StrToInt(tt,10)) END;
  2264.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2265.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2266.     tt := FindToolType(icon.toolTypes,"LEFT");       IF (tt # NIL) THEN left  := SHORT(StrToInt(tt,10)) END;
  2267.     tt := FindToolType(icon.toolTypes,"TOP");        IF (tt # NIL) THEN top   := SHORT(StrToInt(tt,10)) END;
  2268.     tt := FindToolType(icon.toolTypes,"WIDTH");      IF (tt # NIL) THEN width := SHORT(StrToInt(tt,10)) END;
  2269.     tt := FindToolType(icon.toolTypes,"HEIGHT");     IF (tt # NIL) THEN height:= SHORT(StrToInt(tt,10)) END;
  2270.     tt := FindToolType(icon.toolTypes,"WINDOW");     IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN win := w END;
  2271.     FreeDiskObject(icon);
  2272.   END;
  2273. END ParseIcon;
  2274.  
  2275.  
  2276. (*------------------------------  MAIN:  ----------------------------------*)
  2277.  
  2278. BEGIN
  2279.  
  2280. (*------  Init:  ------*)
  2281.  
  2282.   mySigBit := -1;
  2283.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2284.   meInt := SYS.VAL(LONGINT,Me);
  2285.   OldDir := Me.currentDir;
  2286.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2287.   WriteName := "PRT:";
  2288.   MemIndex := ChunkSize;
  2289.   Sync := w;
  2290.   FontSize := 8;
  2291.   Pattern := "~(#?.info)";
  2292.   editcmd := 'C:Ed';
  2293.   id := g.invalidID;
  2294.   tabw := 8;
  2295.   depth := 2;
  2296.   left   := 0;
  2297.   top    := 10;
  2298.   width  := 640;
  2299.   height := 190;
  2300.  
  2301.   IF (I.base.libNode.version < 37) OR (g.base.libNode.version < 37) THEN
  2302.     HALT(d.fail);
  2303.   END;
  2304.  
  2305.  
  2306.   mySigBit := e.AllocSignal(-1);
  2307.   IF mySigBit<0 THEN HALT(d.fail) END;
  2308.   mySig := LONGSET{mySigBit};
  2309.  
  2310.   iconBase := e.OpenLibrary("icon.library",33);
  2311.  
  2312.   IF loc.base # NIL THEN
  2313.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2314.   END;
  2315.  
  2316.   ol.OutOfMemHandler := OutOfMemHandler;
  2317.  
  2318.   INCL(ol.MemReqs,e.public);
  2319.  
  2320.   ol.New(ShowStack,ShowStackSize);
  2321.   NEW(ShowTask);
  2322.   NEW(FileInfo);
  2323.   NEW(ievent);
  2324.   NEW(conreq);
  2325.   NEW(Buffer);
  2326.  
  2327.   INCL(ol.MemReqs,e.chip);
  2328.   NEW(busyPointer);
  2329.   e.CopyMem(TheBusyPointer,busyPointer^,SIZE(busyPointer^));
  2330.   EXCL(ol.MemReqs,e.chip);
  2331.  
  2332. (*------  Setup:  ------*)
  2333.  
  2334.   NEW(FirstLine);
  2335. (*FirstLine.size := 0;
  2336.   FirstLine.text[0] := 0X; *)
  2337.  
  2338. (*------  Start:  ------*)
  2339.  
  2340.   LoadPrefs;
  2341.  
  2342.   IF ol.wbStarted THEN
  2343.  
  2344.     wbm := ol.wbenchMsg;
  2345.     IF iconBase # NIL THEN
  2346.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2347.       FOR i := 0 TO j-1 DO
  2348.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2349.         nameptr := wbm.argList[i].name;
  2350.         icon := GetDiskObject(nameptr^);
  2351.         IF icon=NIL THEN
  2352.           IF d.base.lib.version >= 37 THEN
  2353.             SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2354.             icon := GetDiskObject(nameptr^);
  2355.           END;
  2356.           IF icon=NIL THEN
  2357.             clock := d.Lock("C:",d.sharedLock);
  2358.             SYS.SETREG(0,d.CurrentDir(clock));
  2359.             icon := GetDiskObject(nameptr^);
  2360.           END;
  2361.         END;
  2362.         ParseIcon(icon);
  2363.       END;
  2364.     END; (* IF iconBase#NIL *)
  2365.  
  2366.     IF wbm.numArgs >= 2 THEN
  2367.       ArgPtr := wbm.argList^[1].name; Name := ArgPtr^;
  2368.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2369.     ELSE
  2370.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2371.       FileReq(Name)
  2372.     END;
  2373.     IF clock # NIL THEN d.UnLock(clock) END;
  2374.  
  2375.   ELSE
  2376.  
  2377.     IF iconBase # NIL THEN
  2378.       progdir := d.GetProgramDir();
  2379.       IF progdir = NIL THEN
  2380.         progdir := d.Lock("C:",d.sharedLock); cLocked := w;
  2381.       END;
  2382.       oldcd := d.CurrentDir(progdir);
  2383.       IF d.GetProgramName(Name,LEN(Name)) THEN
  2384.         icon := GetDiskObject(Name);
  2385.         ParseIcon(icon);
  2386.         Name[0] := 0X;
  2387.       END;
  2388.       oldcd := d.CurrentDir(oldcd);
  2389.       IF cLocked THEN d.UnLock(progdir) END;
  2390.     END;
  2391.  
  2392.     rd := d.ReadArgs("B=PLANES/N/K,C=PALETTE/K,D=DISPMODEREQ/S,E=EDITOR/K,F=FONT/K,O=OLDSTYLE/S,P=TOOLPRI/N/K,T=TABWIDTH/N/K,X=EXTRASPACE/N/K,W=WINDOW/S,WL=LEFT/N/K,WT=TOP/N/K,WW=WIDTH/N/K,WH=HEIGHT/N/K,FILE",args,NIL);
  2393.     IF rd=NIL THEN
  2394.       SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2395.       HALT(d.warn)
  2396.     END;
  2397.     IF args.b # NIL THEN depth := SHORT(args.b^) END;
  2398.     IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2399.     IF args.d # NIL THEN modeReq := w END;
  2400.     IF args.e # NIL THEN COPY(args.e^,editcmd) END;
  2401.     IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2402.     IF args.o # NIL THEN oldstyle := w END;
  2403.     IF args.p # NIL THEN taskpri := SHORT(SHORT(args.p^)) END;
  2404.     IF args.t # NIL THEN tabw := SHORT(args.t^) END;
  2405.     IF args.x # NIL THEN spacing := SHORT(args.x^) END;
  2406.     IF args.w # NIL THEN win := w END;
  2407.  
  2408.     IF args.wl # NIL THEN left  := SHORT(args.wl^) END;
  2409.     IF args.wt # NIL THEN top   := SHORT(args.wt^) END;
  2410.     IF args.ww # NIL THEN width := SHORT(args.ww^) END;
  2411.     IF args.wh # NIL THEN height:= SHORT(args.wh^) END;
  2412.  
  2413.     IF args.file # NIL THEN COPY(args.file^,Name) END;
  2414.     d.FreeArgs(rd); rd := NIL;
  2415.   END;
  2416.  
  2417.   IF taskpri#oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2418.  
  2419.   IF tabw < 1 THEN tabw := 1 END;
  2420.  
  2421.   IF depth < 1 THEN depth := 1 END;
  2422.   IF depth > 2 THEN depth := 2 END;
  2423.  
  2424.   IF str.Occurs(editcmd,"%s")<0 THEN str.Append(editcmd,' "%s"') END;
  2425.  
  2426.   IF FontName[0]#0X THEN
  2427.     i := 0;
  2428.     j := SHORT(str.Length(FontName));
  2429.     LOOP
  2430.       IF i >= j THEN EXIT END;
  2431.       IF FontName[i]='/' THEN
  2432.         FontName[i] := 0X;
  2433.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2434.         j := i;
  2435.         EXIT
  2436.       END;
  2437.       INC(i);
  2438.     END;
  2439.     IF j<LEN(FontName)-6 THEN
  2440.       e.CopyMem(".font",FontName[j],6);
  2441.     END;
  2442.   END;
  2443.  
  2444.   IF Pens[0]#0X THEN
  2445.     ci := 0;
  2446.     chptr := SYS.ADR(Pens);
  2447.     Pens[LEN(Pens)-1] := 0X;
  2448.     LOOP
  2449.       Cols[ci] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2450.       INC(ci); IF ci=4 THEN EXIT END;
  2451.       WHILE (chptr^#0X) & (chptr^#",") DO
  2452.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2453.       END;
  2454.       IF chptr^="," THEN
  2455.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2456.       ELSE
  2457.         EXIT
  2458.       END;
  2459.     END;
  2460.   END;
  2461.  
  2462.   IF FontSize>50 THEN FontSize := 50 END;
  2463.   IF FontSize< 5 THEN FontSize :=  5 END;
  2464.  
  2465.   IF spacing< 0 THEN spacing :=  0 END;
  2466.   IF spacing>20 THEN spacing := 20 END;
  2467.  
  2468.   IF width <150 THEN width  := 150 END;
  2469.   IF height< 70 THEN height :=  70 END;
  2470.  
  2471.   IF modeReq & (gt.base#NIL) THEN
  2472.     IF ScreenModeReq(id) = 1 THEN SavePrefs END;
  2473.   END;
  2474.  
  2475. (*------  Open File:  ------*)
  2476.  
  2477.   LOOP
  2478.     MyFile := d.Open(Name,d.oldFile);
  2479.     IF MyFile#NIL THEN EXIT END;
  2480.     FileReq(Name)
  2481.   END;
  2482.  
  2483. (*------------------------  Open Display:  --------------------------------*)
  2484.  
  2485. (*------  Open Screen:  ------*)
  2486.  
  2487.   IF ~win THEN
  2488.  
  2489.     LOOP
  2490.   
  2491.       IF id=g.invalidID THEN
  2492.         id := g.defaultMonitorID;
  2493.         pub := I.LockPubScreen(NIL);
  2494.         IF pub # NIL THEN
  2495.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  2496.           I.UnlockPubScreen(NIL,pub);
  2497.         END;
  2498.       END;
  2499.   
  2500.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  2501.         width  := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  2502.         height := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  2503.   
  2504.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  2505.           lace := g.isLace IN disp.propertyFlags;
  2506.           Scrollable := (g.isDraggable IN disp.propertyFlags);
  2507.           IF Scrollable THEN INC(height,height) END;
  2508.   
  2509.           Screen := I.OpenScreenTagsA(NIL,
  2510.                                      I.saLeft,      0,
  2511.                                      I.saTop,       0,
  2512.                                      I.saWidth,     width,
  2513.                                      I.saHeight,    height,
  2514.                                      I.saDepth,     depth,
  2515.                                      I.saDisplayID, id,
  2516.                                      I.saOverscan,  I.oScanText,
  2517.                                      I.saPens,      SYS.ADR("\xFF\xFF"),
  2518.                                      I.saQuiet,     I.LTRUE,
  2519.                                      u.end);
  2520.         END;
  2521.       END;
  2522.   
  2523.       IF Screen#NIL THEN EXIT END;
  2524.   
  2525.       DEC(depth);
  2526.       IF depth=0 THEN Request(LocStr(MSGCOS)^) END;
  2527.     END;
  2528.   
  2529.     rp := SYS.ADR(Screen.rastPort);
  2530.     BM := rp.bitMap;
  2531.     ri := Screen.viewPort.rasInfo;
  2532.   
  2533.     IF ci>0 THEN g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,ci) END;
  2534.  
  2535.     left := 0;
  2536.     top  := 0;
  2537.     width  := Screen.width;
  2538.     height := Screen.height;
  2539.  
  2540.   END;
  2541.  
  2542.  
  2543. (*------  Open Window:  ------*)
  2544.  
  2545.   IF win THEN
  2546.  
  2547.     Window := I.OpenWindowTagsA(NIL,
  2548.                                 I.waTitle,   SYS.ADR(MuchText),
  2549.                                 I.waLeft,    left,
  2550.                                 I.waTop,     top,
  2551.                                 I.waWidth,   width,
  2552.                                 I.waHeight,  height,
  2553.                                 I.waIDCMP,   MyIdcmp,
  2554.                                 I.waFlags,   LONGSET{I.windowDrag,I.windowClose,I.windowDepth,I.rmbTrap,I.activate,I.noCareRefresh},
  2555.                                 u.done);
  2556.     rp := Window.rPort;
  2557.     left   := Window.borderLeft;
  2558.     top    := Window.borderTop;
  2559.     width  := Window.gzzWidth;
  2560.     height := Window.gzzHeight;
  2561.     Scrollable := FALSE;
  2562.  
  2563.   ELSE
  2564.  
  2565.     Window := I.OpenWindowTagsA(NIL,
  2566.                                 I.waLeft,    0,
  2567.                                 I.waTop,     10,
  2568.                                 I.waWidth,   width,
  2569.                                 I.waHeight,  height-10,
  2570.                                 I.waCustomScreen,Screen,
  2571.                                 I.waIDCMP,   MyIdcmp,
  2572.                                 I.waFlags,   LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop},
  2573.                                 u.done);
  2574.   END;
  2575.  
  2576.   IF Window=NIL THEN Request(LocStr(MSGCOW)^) END;
  2577.  
  2578. (*------  Open Font:  ------*)
  2579.  
  2580.   IF FontName[0]#0X THEN
  2581.     MyAttr.name := SYS.ADR(FontName);
  2582.     MyAttr.ySize := FontSize;
  2583.     IF diskFontBase=NIL THEN diskFontBase := e.OpenLibrary("diskfont.library",33) END;
  2584.     IF diskFontBase#NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  2585.     IF (MyFont#NIL) & ~(g.proportional IN MyFont.flags) THEN g.SetFont(rp,MyFont) END;
  2586.   END;
  2587.  
  2588.   LOOP
  2589.     fontWidth  := rp.font.xSize;
  2590.     fontHeight := rp.font.ySize;
  2591.     IF (fontWidth<=50) OR (fontHeight<=50) & (fontWidth>2) & (fontHeight>2) THEN EXIT END;
  2592.     MyAttr.name := SYS.ADR("topaz.font");
  2593.     MyAttr.ySize := 8;
  2594.     MyFont := g.OpenFont(MyAttr);
  2595.     IF MyFont=NIL THEN HALT(d.fail) END;
  2596.     g.SetFont(rp,MyFont);
  2597.   END;
  2598.   INC(fontHeight,spacing);               (* extra spacing *)
  2599.   fontBaseLine := rp.font.baseline;
  2600.  
  2601.   NumColumns := width DIV fontWidth;
  2602.   IF Scrollable THEN NumLines   := (height DIV 2) DIV fontHeight;
  2603.                 ELSE NumLines   := height DIV fontHeight; END;
  2604.   PageHeight := fontHeight*NumLines;
  2605.   height :=     PageHeight;
  2606.  
  2607.   ClearDisplay;
  2608.  
  2609.   IF Scrollable THEN
  2610.     Screen.height := height;
  2611.     I.OldMakeScreen(Screen);
  2612.     I.OldRethinkDisplay;
  2613.   ELSIF win THEN
  2614.     INC(top,(Window.gzzHeight-height) DIV 2);
  2615.   END;
  2616.  
  2617. (*------  Get KeyMap:  ------*)
  2618.  
  2619.   IF e.OpenDevice("console.device",-1,conreq,LONGSET{})#0 THEN HALT(d.fail) END;
  2620.   console := conreq.device;
  2621.   con.base := console;
  2622. (*ievent.nextEvent := NIL;
  2623.   ievent.qualifier := {};
  2624.   ievent.eventAddress := NIL; *)
  2625.   ievent.class := ie.rawkey;
  2626.  
  2627.   FOR i := 0 TO 3FH DO
  2628.     ievent.code := i;
  2629.     SYS.SETREG(0,con.RawKeyConvert(ievent,KeyMap[i],16,NIL));
  2630.   END;
  2631.  
  2632. (*------  Decrunch:  ------*)
  2633.  
  2634.   Decrunch;
  2635.  
  2636. (*------  Init 2nd Task:  ------*)
  2637.  
  2638.   ShowTask.spLower := ShowStack;
  2639.   ShowTask.spUpper := SYS.VAL(e.APTR,SYS.VAL(LONGINT,ShowStack) + ShowStackSize);
  2640.   ShowTask.spReg   := ShowTask.spUpper;
  2641.   ShowTask.node.type := e.task;
  2642.   ShowTask.node.name := SYS.ADR("mm.show");
  2643.   ShowTask.node.pri  := Me.task.node.pri+1;
  2644.   (* $IF SmallData *)
  2645.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2646.   (* $END *)
  2647.  
  2648.   e.Forbid;
  2649.    e.AddTask(ShowTask,ShowProc,NIL);
  2650.    ShowTaskRunning := w;
  2651.    Window.userPort.sigTask := ShowTask;
  2652.   e.Permit;
  2653.  
  2654. (*------  Main Load / Display Loop:  ------*)
  2655.  
  2656.   LOOP
  2657.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2658.     RQLen := -1; RQPos := -1;
  2659.     AnzLines := 1;
  2660.     LastLine := FirstLine;
  2661.     BottomLine := FirstLine;
  2662.     TopLine    := FirstLine;
  2663.     TextLength := 0;
  2664.     FindLine   := NIL;
  2665.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2666.  
  2667.     MyLock := d.Lock(Name,d.sharedLock);
  2668.     IF MyLock=NIL THEN Request(LocStr(MSGCOF)^) END;
  2669.     IF ~ d.Examine(MyLock,FileInfo^) THEN Request(LocStr(MSGCOF)^) END;
  2670.     FileLength := FileInfo.size;
  2671.  
  2672.     d.UnLock(MyLock); MyLock := NIL;
  2673.     IF FileLength=0 THEN Request(LocStr(MSGEMPTY)^) END;
  2674.  
  2675.     (*------  Start displaying & Loading:  ------*)
  2676.  
  2677.     NewDisp := w;
  2678.  
  2679.     e.Signal(ShowTask,mySig);
  2680.  
  2681.     REPEAT
  2682.       LoadLine := GetTextLine();
  2683.       IF LoadLine=NIL THEN
  2684.         d.OldClose(MyFile); MyFile := NIL;
  2685.       ELSE
  2686.         LoadLine.prev := LastLine;
  2687.         LastLine.next := LoadLine;
  2688.         LastLine := LoadLine;
  2689.       END;
  2690.       IF SignalNewData THEN e.Signal(ShowTask,mySig) END;
  2691.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2692.     IF SignalAllRead THEN e.Signal(ShowTask,mySig) END;
  2693.     REPEAT
  2694.       SYS.SETREG(0,e.Wait(mySig));
  2695.       IF print THEN
  2696.         in  := d.Open("NIL:",d.newFile);
  2697.         IF d.SystemTags(PStr,d.sysInput,    SYS.VAL(e.APTR,in),
  2698.                              d.sysOutput,   NIL,
  2699.                              d.sysAsynch,   d.DOSTRUE,
  2700.                              d.sysUserShell,d.DOSTRUE,
  2701.                              u.done)                   = -1 THEN
  2702.           d.OldClose(in);
  2703.         ELSE
  2704.           Decrunched := f; INC(meInt);
  2705.         END;
  2706.         in := NIL;
  2707.         print := f;
  2708.       END;
  2709.       IF save THEN
  2710.         in := d.Open(Name,d.oldFile);
  2711.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2712.           ol.New(buffer,savesize);
  2713.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2714.           IF d.Read(in,buffer^,savesize)#savesize THEN
  2715.             I.DisplayBeep(NIL);
  2716.             d.OldClose(in); in := NIL;
  2717.           ELSE
  2718.             d.OldClose(in); in := NIL;
  2719.             IF copy THEN
  2720.               iff := NIL;
  2721.               LOOP
  2722.                 IF ip.base=NIL THEN EXIT END;
  2723.                 iff := ip.AllocIFF();
  2724.                 IF iff=NIL THEN EXIT END;
  2725.                 iff.stream := SYS.VAL(LONGINT,ip.OpenClipboard(0));
  2726.                 IF iff.stream=NIL THEN EXIT END;
  2727.                 ip.InitIFFasClip (iff);
  2728.                 IF (ip.OpenIFF  (iff, ip.write) = 0) &
  2729.                    (ip.PushChunk(iff, SYS.VAL(LONGINT,"FTXT"), ip.idFORM, ip.sizeUnknown)=0) &
  2730.                    (ip.PushChunk(iff, 0, SYS.VAL(LONGINT,"CHRS"), ip.sizeUnknown)=0) &
  2731.                    (ip.WriteChunkBytes(iff,buffer^,savesize) = savesize) &
  2732.                    (ip.PopChunk (iff)=0) &
  2733.                    (ip.PopChunk (iff)=0) THEN
  2734.                 END;
  2735.                 EXIT;
  2736.               END;
  2737.               IF iff#NIL THEN
  2738.                 ip.CloseIFF(iff);
  2739.                 IF iff.stream#0 THEN ip.CloseClipboard (SYS.VAL(e.APTR,iff.stream)) END;
  2740.                 ip.FreeIFF (iff);
  2741.               END;
  2742.             ELSE
  2743.               out := d.Open(WriteName,d.newFile);
  2744.               IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2745.                 IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2746.                 d.OldClose(out); out := NIL;
  2747.               END;
  2748.             END;
  2749.           END;
  2750.           DISPOSE(buffer);
  2751.         END;
  2752.         save := f;
  2753.       END;
  2754.       IF Done THEN EXIT END;
  2755.     UNTIL NewText;
  2756.     IF MyFile#NIL THEN d.OldClose(MyFile); MyFile := NIL END;
  2757.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2758.     Decrunched := f;
  2759.     DisposeLines();
  2760.     FirstLine^.next := NIL; NewText := f;
  2761.     Name := OldName;
  2762.     REPEAT
  2763.       FileReq(Name);
  2764.       MyFile := d.Open(Name,d.oldFile);
  2765.     UNTIL MyFile#NIL;
  2766.     Decrunch;
  2767.   END;   (* LOOP *)
  2768.  
  2769. CLOSE
  2770.  
  2771.   IF Win         # NIL THEN I.CloseWindow(Win)               END;
  2772.   IF ShowTaskRunning   THEN e.RemTask(ShowTask)              END;
  2773.   IF console     # NIL THEN e.CloseDevice(conreq)            END;
  2774.   g.WaitBlit;
  2775.   IF Window      # NIL THEN I.CloseWindow(Window)            END;
  2776.   IF Screen      # NIL THEN I.OldCloseScreen(Screen)         END;
  2777.   IF MyFont      # NIL THEN g.CloseFont(MyFont)              END;
  2778.   IF MyFile      # NIL THEN d.OldClose(MyFile)               END;
  2779.   IF in          # NIL THEN d.OldClose(in)                   END;
  2780.   IF out         # NIL THEN d.OldClose(out)                  END;
  2781.   IF Decrunched        THEN SYS.SETREG(0,d.DeleteFile(Name)) END;
  2782.   IF xpk         # NIL THEN e.CloseLibrary(xpk)              END;
  2783.   IF asl         # NIL THEN e.CloseLibrary(asl)              END;
  2784.   IF diskFontBase# NIL THEN e.CloseLibrary(diskFontBase)     END;
  2785.   IF iconBase    # NIL THEN e.CloseLibrary(iconBase)         END;
  2786.   IF mySigBit >= 0     THEN e.FreeSignal(mySigBit)           END;
  2787.   IF catalog     # NIL THEN loc.CloseCatalog(catalog);       END;
  2788.   IF taskpri # oldpri  THEN oldpri := e.SetTaskPri(Me,oldpri)END;
  2789.   OldDir := d.CurrentDir(OldDir);
  2790.  
  2791. END MuchMore.
  2792.  
  2793.